Skip to content

assigning to immutable argument produces a confusing error #46659

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
nikomatsakis opened this issue Dec 11, 2017 · 3 comments
Closed

assigning to immutable argument produces a confusing error #46659

nikomatsakis opened this issue Dec 11, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@nikomatsakis
Copy link
Contributor

This program:

fn foo(_x: u32) {
    _x = 4;
}

fn main() {}

produces this error:

error[E0384]: re-assignment of immutable variable `_x`
 --> src/main.rs:2:5
  |
1 | fn foo(_x: u32) {
  |        -- first assignment to `_x`
2 |     _x = 4;
  |     ^^^^^^ re-assignment of immutable variable

I consider this a somewhat confusing error. I think it should rather be:

error[E0384]: assignment of immutable argument `_x`
 --> src/main.rs:2:5
  |
1 | fn foo(_x: u32) {
  |        -- `_x` not declared as `mut`
2 |     _x = 4;
  |     ^^^^^^ assignment of immutable argument `_x`

perhaps with a suggestion or something.

This error is issued by the borrow checker, so to do this right we should also modify the MIR-based borrow checker.

@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints E-needs-mentor T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics labels Dec 11, 2017
@nikomatsakis
Copy link
Contributor Author

cc @estebank

bors added a commit that referenced this issue Jan 14, 2018
Assignment to immutable argument: diagnostic tweak

Re #46659.
@nikomatsakis
Copy link
Contributor Author

Looks like this was fixed by #47261

@estebank
Copy link
Contributor

Only for MIR, that's why I didn't close the ticket, but if that's not a problem let's leave it closed.

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

2 participants