Skip to content

"cannot assign to immutable field" could be confusing #35937

Closed
@durka

Description

@durka
struct S { x: i32 }
let s = S { x: 42 };
s.x += 1; //~ERROR cannot assign to immutable field

It occurred to me that this might be confusing to newcomers because fields don't have mutability in Rust, instead we have inherited mutability. So maybe it should say "cannot assign to field of immutable struct" or "cannot modify field due to immutable binding" or something.

cf #18150

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions