reference
reference copied to clipboard
Document what `mut` does in identifier patterns
The syntax is documented in the reference: https://doc.rust-lang.org/stable/reference/patterns.html#identifier-pattern, but afaict not the meaning.
Impact
Experienced users can still get tripped up by things like: https://stackoverflow.com/questions/69845063/why-does-a-level-of-indirection-allow-omitting-mut (I'm a Rust n00b, but posted the question for a Rust-experienced colleague).
How to fix:
If someone has a definition of mut
handy, I can make PRs to update relevant parts of the docs. Apologies if mut
is already defined and I missed it.
moved from https://github.com/rust-lang/rust/issues/90605
how about
mut ident
means you can create mutable references toident
that can last as long asident
, which you cannot do with immutable bindings. You can also assign to a variable that is mutable to change its value. This is simliar to shadowing, except you cannot assign it to a differently typed expression, which you can with shadowing. Also, a shadowed variable "retains" its previous type and value. After it goes out of scope, it "returns" to its previous value and type. While assigning to a mutable variable changes its value for the rest of its lifetime.