The special warning against transmute(&T)-> &mut T

Yes, this is correct. Rust will pass noalias attributes for all &mut T, and readonly for all &T to LLVM, unless they contain an UnsafeCell. The compiler has knowledge of UnsafeCell thanks to this lang item.

LLVM will move stores/loads of a noalias pointer for optimization purposes. If the pointer actually is aliased, by part of it being able to transmute into a &mut T, then that violates the noalias contract, which could be re-ordered. This likely won’t cause issues if the function only has loads, so it may cause undefined behavior.

4 Likes