Skip to content

Multiple errors for the same missing mut #53466

Closed
@RalfJung

Description

@RalfJung

For the following program

fn main() {
    let v = Vec::new();
    v.push(0);
    v.push(0);
}

rustc shows two errors:

error[E0596]: cannot borrow immutable local variable `v` as mutable
 --> src/main.rs:3:5
  |
2 |     let v = Vec::new();
  |         - consider changing this to `mut v`
3 |     v.push(0);
  |     ^ cannot borrow mutably

error[E0596]: cannot borrow immutable local variable `v` as mutable
 --> src/main.rs:4:5
  |
2 |     let v = Vec::new();
  |         - consider changing this to `mut v`
3 |     v.push(0);
4 |     v.push(0);
  |     ^ cannot borrow mutably

error: aborting due to 2 previous errors

These are not exactly the same, but still pretty much a duplicate.

it would be nice if rustc could avoid complaining about the same thing twice here.

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.D-papercutDiagnostics: An error or lint that needs small tweaks.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