Skip to content

Use structured suggestion when missing mut on local binding #54133

Closed
@estebank

Description

@estebank

The following code:

use std::collections::HashMap;

fn main() {
    let x = HashMap::new();
    x.insert("a", 3);
    println!("{:?}", x.get("a"));
}

Produces

error[E0596]: cannot borrow immutable local variable `x` as mutable
 --> src/main.rs:5:5
  |
4 |     let x = HashMap::new();
  |         - consider changing this to `mut x`
5 |     x.insert("a", 3);
  |     ^ cannot borrow mutably

The suggestion for line 4 is a label, not a suggestion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions