I'm not sure if this is a bug or not.
I tried this code:
#![allow(dead_code)]
struct NotCopy { data: i32 }
fn main() {
let ref x @ ref y = NotCopy { data: 1 };
assert!(std::ptr::eq(x, y));
}
I ran the above code in Miri. The assertion failed.
It seems to me that the NotCopy constant is const-promoted twice, resulting in two implicit NotCopy statics. (I'm guessing that, outside of miri, the consts happen to be deduplicated.)
As a result, it is observable whether const promotion happened or not. In my understanding, promotion is supposed to happen only when it's not observable whether it has happened. Therefore, I think this behavior is incorrect.
See also #145237, where a constant is both moved and promoted.
@rustbot labels +T-lang +A-patterns +A-const-eval
Meta
Reproducible on the playground in version 1.91.0-nightly (2025-08-17 425a9c0a0e365c0b8c6c)
I'm not sure if this is a bug or not.
I tried this code:
I ran the above code in Miri. The assertion failed.
It seems to me that the
NotCopyconstant is const-promoted twice, resulting in two implicitNotCopystatics. (I'm guessing that, outside of miri, the consts happen to be deduplicated.)As a result, it is observable whether const promotion happened or not. In my understanding, promotion is supposed to happen only when it's not observable whether it has happened. Therefore, I think this behavior is incorrect.
See also #145237, where a constant is both moved and promoted.
@rustbot labels +T-lang +A-patterns +A-const-eval
Meta
Reproducible on the playground in version
1.91.0-nightly (2025-08-17 425a9c0a0e365c0b8c6c)