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
On Windows a static address changes when copied into another static across a module boundary #127518
But also since we fixed this for Linux, I assume there's some specific Windows interaction here. And all I know about linking on Windows is that it is a lot more complicated than on Linux, and I already don't really understand linking on Linux...
Not sure we're protecting against this on linux either. It just works by accident. the address of string literals is not stable. this won't be an issue on windows either if you use [u8] and let x = [42]; &x for IN_MOD's initializer, as that creates an anonymous nested static
But it's hard to express this entirely syntactically. @oli-obk do we have a MIR body for the pointed-to think or only the reference? I thought it was only for the reference.
Activity
workingjubilee commentedon Jul 9, 2024
...that's so weird I'm not even entirely sure it's a bug.
bjorn3 commentedon Jul 10, 2024
cc @RalfJung
RalfJung commentedon Jul 10, 2024
Cc @oli-obk
RalfJung commentedon Jul 10, 2024
But also since we fixed this for Linux, I assume there's some specific Windows interaction here. And all I know about linking on Windows is that it is a lot more complicated than on Linux, and I already don't really understand linking on Linux...
Cc @ChrisDenton @mati865
oli-obk commentedon Jul 10, 2024
Not sure we're protecting against this on linux either. It just works by accident. the address of string literals is not stable. this won't be an issue on windows either if you use
[u8]andlet x = [42]; &xforIN_MOD's initializer, as that creates an anonymous nested staticRalfJung commentedon Jul 10, 2024
Ah the nested static stuff doesn't fire for string literals?
Makes sense. In that case this is not-a-bug. If the issue also crops up without the use of string/byte literals, that would be a different case.
Alexendoo commentedon Jul 10, 2024
It also occurs with structs:
I originally ran into this with
declare_lintas it produces a&'static Lint, it's why there's this workaround in Clippyrust/src/tools/clippy/clippy_lints/src/lib.rs
Lines 482 to 483 in 0fdfb61
RalfJung commentedon Jul 10, 2024
Yeah
&super::Foo { a: 1 }is implicitly promoted here. The intended way to write this isoli-obk commentedon Jul 10, 2024
or
Alexendoo commentedon Jul 10, 2024
The
letversion gives a lifetime errorRegarding promotion am I right in thinking that
turns into something like the following?
oli-obk commentedon Jul 10, 2024
oopos, need to use
&{x}to move out of thex💀RalfJung commentedon Jul 10, 2024
AFAIK it's more like
References in constants have no pointer identity guarantees.
Ofc that does not explain how the
constitself is accepted so maybe it should beBut it's hard to express this entirely syntactically. @oli-obk do we have a MIR body for the pointed-to think or only the reference? I thought it was only for the reference.
oli-obk commentedon Jul 10, 2024
yea, that's right. We used to do it differently, but that had its own problems.
workingjubilee commentedon Jun 19, 2025
Based on the previous conversation I am closing this as it is non-intuitive but also not-a-bug.
RalfJung commentedon Jun 20, 2025
I think we do eventually want to fix this, but that is tracked at #128775.