Does UnsafeCell make the coexistence of &mut T legal?
โ Rust ๐ 2026-02-21 ๐ค surdeus ๐๏ธ 1Iโm trying to verify my understanding of Rustโs aliasing rules regarding UnsafeCell<T>.
It seems that if you have multiple &UnsafeCell<T> references and use one to create a temporary &mut T for writing, you inevitably have both types of pointers pointing to the same memory at the same time.
My reasoning is that since UnsafeCell<T> explicitly opts out of the standard &T immutability/noalias guarantees, this "coexistence" might actually be legal within the memory model. Is it correct to say that as long as UnsafeCell is involved, the strict exclusivity of &mut T is relaxed to allow these overlaps?
Iโd appreciate any insights on whether this interpretation is correct.
10 posts - 5 participants
๐ท๏ธ Rust_feed