On replacing UnsafeCell
Rust Internals [Unofficial]
March 26, 2026
ProgramCrafter:
structs are now also allowed to have twilight fields which are internally mutable and potentially uninitialized
I'm generally opposed to any feature which makes fields not uphold their usual invariants. If the field is i32 and you can get an &i32, that should be a legal &i32, but that doesn't hold here.
The wrapper type is really useful because getting a &UnsafeCell<i32> is perfectly fine -- it can be passed around, it can have Debug defined on the unsafecell so that derive(Debug) works, etc.
Attributes that add extra guarantees is fine -- a &i32 to a field with #[align(128)] is still usable, for example -- but removing type things is best done with a wrapper, not an attribute.
Discussion in the ATmosphere