Personally, I find it a bit difficult to properly explain what mut
in patterns does exactly while teaching Rust. The naive "mutable variable" explanation immediately breaks down under numerous exceptions (let y = &mut x;
, interior mutability, etc.), so lately I explain it as a "hard lint" which allows creation of mut
references from the variable.
It may have been useful to allow us specify additional properties for variable bindings, like "does not/may/does contain interior mutability", "does not/may/does heap allocations", "read-only data", "write-only data", etc. But it quickly becomes a matter of practicality. Would you like to see let mut interior_mutability no_heap x = ...;
for every variable? Sure, we may make some of those properties optional (i.e. they would default to "may"), but it would mean creation of different Rust dialects "noisy, but precise" and "imprecise, but lean".
The same applies to references. In some cases it can be useful to guarantee that a reference is "write only" or "does not contain any interior mutability", but every granular property is an additional piece of information which makes code more difficult to read and write. Whether such trade-off is worthwhile depends on the programmer and the area of use.