The situation:
src/jostletree.rs:22:45: 22:54 error: mutating transmuted &mut T from &T may cause undefined behavior,consider instead using an UnsafeCell, #[deny(mutable_transmutes)] on by default
src/jostletree.rs:22 unsafe fn warp_into_mut<T>(v:&T)-> &mut T { transmute(v) }
My issue:
I believed I understood all of the reasons warp_into_mut could be problematic. I know about the litany of problems one can encounter with aliased mutable pointers in multithreaded contexts. I know about the difference between copy and copy_nonoverlapping. None of that is happening in my use case. (dunno if this sums it up well but basically all I’m doing is wrapping a fn(&T)->&T as a fn(&mut T)-> &mut T)
Now, rustc comes along and warns me me that doing that is not just unsafe, but possibly undefined behavior (and “may cause undefined behavior” dangerously close to “undefined behavior”). That’s a whole other barrel of tentacles. Then it tells me about this UnsafeCell thing, which seems to be basically a *mut, but then the folks on IRC tell me it is bestowed with magic that *muts know not.
Nowhere does it seem to be explained why this conversion should be considered such a special kind of dangerous black magic.
So I thought it’d be worth asking here.