Closed as not planned
Description
miri creates two allocations for the *b"hi"
in A
.
see MIR in https://is.gd/bCUD7p
This makes sense, since there's _1 = A; _2 = &_1
instead of _2 = &A
.
Should this
a) be fixed in rustc, or
b) should we cache all literals (we have FIXMEs for that), or
c) should we add some Cow
-like structure to lvalues, so they can refer to other lvalues "ByVal"?
d) is the test ( https://github.com/rust-lang/rust/blob/master/src/test/run-pass/const-str-ptr.rs ) wrong?
@eddyb: any preferences?
Found more evidence for b and against d:
#![feature(const_fn)]
const fn foo() -> *const i8 {
b"foo" as *const _ as *const i8
}
const fn bar() -> i32 {
*&{(1, 2, 3).1}
}
fn main() {
assert_eq!(foo(), b"foo" as *const _ as *const i8);
assert_eq!(bar(), 2);
}