๐Ÿ“Aliasing only matters if a reference is aliased with another mutable reference

If the object is immutable (as is the case in purely-functional languages), aliasing does not matter. Analysis is never invalidated because objects do not change, and compiler is free to cache values.

In Rust, mutable references never alias, which is guaranteed by the type system. If you have a read-only reference, it is guaranteed that there is no other write reference to the same object. Therefore, nobody can change the value, so compiler is free to perform optimizations.

See also

Backlinks