Description
Brought up by @saethlin around here: rust-lang/rust#92092 fixes a standard library issue where
there is a mutable reference which is used only for reads becomes invalid as a result of interior mutation of the referent, where a shared reference does not become invalid.
So, this is a case where using a shared ref rather than a mutable ref was more correct, in the face of mutation inside an UnsafeCell
.
I have to say I consider this fully intended, the promise of a mutable reference is uniqueness and UnsafeCell
deliberately has no effect on &mut
. But it is worth tracking whether violating this rule is a common issue, and whether it might be worth somehow allowing this. The most extreme version of this would in general allow reads through other pointers when using an &mut
(perhaps making the &mut
read-only in the process? that would be a new mechanism in the aliasing model though). But that will severely impact our even entirely remove our ability to reorder writes to mutable references.