-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.P-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.T-langRelevant to the language teamRelevant to the language team
Description
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)
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.I-lang-nominatedNominated for discussion during a lang team meeting.Nominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.P-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.T-langRelevant to the language teamRelevant to the language team