Skip to content

Confusing error message with closures #47774

Closed
@est31

Description

@est31
struct Foo {
    u :u32,
}
impl Foo {
    fn foo(&mut self) {
        || {
            let r = &mut self;
            r.u += 1;
        };
    }
}

gives

error[E0595]: closure cannot assign to immutable argument `self`
 --> src/main.rs:6:9
  |
6 |         || {
  |         ^^
  |         |
  |         cannot reborrow mutably
  |         try removing `&mut` here

error: aborting due to previous error

error: Could not compile `playground`.

Which is very cryptic and doesn't really show what's going on.

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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions