Skip to content

Use structured suggestion when missing mut on local binding #54133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
estebank opened this issue Sep 11, 2018 · 0 comments
Closed

Use structured suggestion when missing mut on local binding #54133

estebank opened this issue Sep 11, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@estebank
Copy link
Contributor

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.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 11, 2018
euclio added a commit to euclio/rust that referenced this issue Sep 12, 2018
bors added a commit that referenced this issue Sep 16, 2018
use structured suggestion for "missing mut" label

Fixes #54133 for both NLL and non-NLL.

r? @estebank

I'm not super happy with the existing wording here, since it's now a suggestion. I wonder if the message would work better as something like "help: make binding mutable: `mut foo`"?

Also, are the `HELP` and `SUGGESTION` comments necessary?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

1 participant