Earlier quoted context omitted.
One of the strange things about Rust is the &UnsafeCell /*mut T dichotomy. &UnsafeCell is easier to work with, and you can soundly acquire &mut T as long as they never overlap, but you can't turn a Box > into a &UnsafeCell and back to a Box > to delete it, because provenance or something. *mut T is harder to work with, this is UB according to miri since you didn't specify `&mut x as *mut i32 as *const i32`: let mut x…
You cannot turn a &T into a Box , because &T borrows T, while Box owns T, and moreover it holds it in a separate allocation, so even &mut T cannot be transformed into Box --- it already lives in some allocated space and whatever there is a reference to, cannot be moved to a new allocation. For moving T you need T, not a reference to T. The case with UnsafeCell substituted in place of T is just a special case. UnsafeC…
> UnsafeCell also owns T, so transforming &mut T into UnsafeCell also doesn't make sense.
I wanted to transform a &mut T into &UnsafeCell (note the &) and copy the reference, to allow shared mutation scoped within the lifetime of the source &mut T. How can this be accomplished?