Skip to content

documentation: meaning of mut in identifier patterns is not documented #90605

Closed
@mheiber

Description

@mheiber

I expected to see this happen: documentation for what mut means in let mut x = 3 and fn foo(mut x: i32)

Instead, this happened:

As far as I can tell, the meaning of mut in identifier patterns is not documented in the Book or the Reference.

The syntax is well-documented in the reference: https://doc.rust-lang.org/stable/reference/patterns.html#identifier-pattern, but not the meaning.

An early chapter of the Rust book gives some examples and contrasts let mut with let but doesn't define mut.

In particular, afaict, neither resource says that upgrading a let to a let mut is allowed, but upgrading a & to an &mut is not generally allowed.

let foo = ...
let mut foo = foo // OK

let bar: &B = ...
let bar: &mut B = &mut*bar // Error

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions