It looks to me like UnsafeCell is not really a type, but rather property of a struct field.
See: moving it, including passing as a function argument or return value, can replace UnsafeCell with a simpler type:
UnsafeCell<T>==T&UnsafeCell<T>==NonNull<T>&mut UnsafeCell<T>==&mut T
And it is about "interior mutability" where said "interior" is often relative to some struct.
Therefore a new language feature could be worked out. Its bikesheddable name is "lit/twilight field dichotomy" (#[feature(twilight_fields)]).
A description of new feature
All ordinary fields of a struct are called lit; structs are now also allowed to have twilight fields which are internally mutable and potentially uninitialized (could be controlled inside an attribute).
struct Foo {
#[twilight] special: String,
common: u32,
}
Access to a twilight field (foo.special) produces a nonnull pointer to the contents (NonNull<String>), regardless of whether foo was owned, or shared reference, or exclusive reference. Again regardless of the origin, this pointer has at least read-write provenance for the String.
The twilight fields are stored together with lit ones, and, importantly, moved along the struct (but considered potentially uninitialized). They are accounted in its size and alignment.
&Foo and &mut Foo do not alias twilight fields (presumably they have no provenance to read or write them, but still allowed to do pointer arithmetic since it's inbounds of a Foo allocation).
Required compiler support
Half of this feature can be implemented with unsafe code; unergonomic it (Rust Playground) may be, but it passes Miri except for the leaked memory (destructors for twilight fields should be worked out). However such a struct has to be constructed in-place; compiler support would allow having it first-class and moving it as needed.
What it would solve
The complications of UnsafeCell, UnsafePinned, !Unpin, ManuallyDrop<Box<_>>, and future's ref aliasing[1]; all kinds of accesses could finally be managed in code.
At a certain cost, though; that
&mut Foodoes no longer provide write access to the whole of its span. âŠī¸