Nice question. stackoverflow.com/q/57259126/379
Conversation
Replying to
There were literally dozens of bugs uncovered in LLVM as part of trying to fix this for Rust. It's also incredibly broken in GCC and it isn't getting fixed there because this incentive doesn't exist. Using restrict is probably a bad idea with either, especially combined with LTO.
1
2
I don't remember the precise rules for restrict off the top of my head, but for noalias in LLVM, it can also largely be applied to immutable references in Rust because it's really about memory dependencies and Rust can track when types have 'internal mutability' via Cell, etc.
The vast majority of immutable references can also be noalias, particularly all the trivial cases like &u32. It's just not going to be possible until LLVM has a better implementation and the Rust memory model for the superset including unsafe code also needs to be ironed out.
1
Since immutable references in Rust actually mean immutable, not an immutable view of something mutable. The exception is if it uses a form of internal mutability (Cell, RefCell) and those safe abstractions need to be implemented via UnsafeCell so the compiler can be fully aware.

