You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pointer to static is not guaranteed_eq to itself. #144584
This is not a bug but expected behavior based on how Rust evaluates const expressions. The compiler cannot guarantee that two pointers to the same static are equal at compile time, so guaranteed_eq correctly returns None.
by definition, taking the address of a static is guaranteed to produce the same pointer every time. the current behavior is just a limitation of the current implementation, not an inherent property of constant evaluation.
However, properly tracking this is likely very hard and the function must be conservative, so right now only comparisons with null can possibly return a value in const eval, and even then only sometimes.
Activity
zachs18 commentedon Jul 28, 2025
Seems like there's a FIXME in the compiler for this:
rust/compiler/rustc_const_eval/src/const_eval/machine.rs
Lines 292 to 298 in 9ba00e0
xonx4l commentedon Jul 29, 2025
This is not a bug but expected behavior based on how Rust evaluates const expressions. The compiler cannot guarantee that two pointers to the same static are equal at compile time, so guaranteed_eq correctly returns None.
asquared31415 commentedon Jul 29, 2025
by definition, taking the address of a static is guaranteed to produce the same pointer every time. the current behavior is just a limitation of the current implementation, not an inherent property of constant evaluation.
However, properly tracking this is likely very hard and the function must be conservative, so right now only comparisons with null can possibly return a value in const eval, and even then only sometimes.
Rollup merge of rust-lang#144885 - zachs18:ptr_guaranteed_cmp_more, r…
Rollup merge of rust-lang#144885 - zachs18:ptr_guaranteed_cmp_more, r…
Rollup merge of rust-lang#144885 - zachs18:ptr_guaranteed_cmp_more, r…
Rollup merge of rust-lang#144885 - zachs18:ptr_guaranteed_cmp_more, r…
Rollup merge of rust-lang#144885 - zachs18:ptr_guaranteed_cmp_more, r…
Rollup merge of rust-lang#144885 - zachs18:ptr_guaranteed_cmp_more, r…
Unrolled build for #144885
Rollup merge of #144885 - zachs18:ptr_guaranteed_cmp_more, r=RalfJung
Rollup merge of #144885 - zachs18:ptr_guaranteed_cmp_more, r=RalfJung