When people use the unsafe keyword are they always taking into account aliasing?
At least you can audit only those places though.
At least you can audit only those places though.
That's why Rust developers don't take kindly to unnecessary unsafe usage, because the audit surface area (and interaction complexity) increases.
Therefore, the optimizer can always assume mutations don't alias. Even UnsafeCell isn't allowed to break the alias rules, it just provides flexibility going from immutable to mutable.
For example consider Slice::swap [1]. This does consider the possibility that the pointers alias, and correctly, because they might point at the same object.
https://doc.rust-lang.org/src/core/slice/mod.rs.html#541-553