Add rustc flag to disable mutable no-aliasing optimizations?

The reasoning is that, since raw pointers are not guaranteed to be valid and can easily cause memory corruption if dereferenced at the wrong time, it should be very clear where you're dereferencing them. There have been proposals before to have a more ergonomic way to do this.

Enough with the emotionally charged language.

References are required to be non-null (allowing Option<&T> to be the same size as &T, where None is represented as a null pointer), dereferenceable (allowing them to be marked as LLVM dereferenceable, which in turn allows LLVM to insert speculative loads), and properly aligned (also used by LLVM). Converting a pointer to a reference is UB if it does not satisfy those criteria. This is longstanding behavior. If you want a pointer that can be anything at all, do not use references.

13 Likes