According to analysis performed by @bjorn3, this code actually leads to two allocations containing 42, i.e., FOO and BAR point to different things. The linker later merges the two, so the issue is currently not directly observable. However, it becomes observable when things are mutable.
I think this is a bug. When a static is defined as pub static BAR: &i32 = crate::a::FOO;, IMO we should guarantee that BAR and FOO have the same value. I see no lee-way here for duplicating the memory they both point to.
Cc @oli-obk
According to analysis performed by @bjorn3, this code actually leads to two allocations containing
42, i.e.,FOOandBARpoint to different things. The linker later merges the two, so the issue is currently not directly observable. However, it becomes observable when things are mutable.I think this is a bug. When a static is defined as
pub static BAR: &i32 = crate::a::FOO;, IMO we should guarantee thatBARandFOOhave the same value. I see no lee-way here for duplicating the memory they both point to.Cc @oli-obk