Skip to content
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

Immutable variable reassignment help message #84144

Closed
jayaddison opened this issue Apr 12, 2021 · 2 comments · Fixed by #84172
Closed

Immutable variable reassignment help message #84144

jayaddison opened this issue Apr 12, 2021 · 2 comments · Fixed by #84172
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jayaddison
Copy link
Contributor

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=513388a632de3de69d34c0ced0483ec6

fn main() {
    let x = 5;
    println!("The value of x is: {}", x);
    x = 6;
    println!("The value of x is: {}", x);
}

The current output is:

...
  |         help: make this binding mutable: `mut x`
...

Ideally the output should look like:

...
  |         help: consider making this binding mutable: `mut x`
...

Maybe it's over-analyzing the messaging, but in a lot of cases we make suggestions from compiler help messages - i.e. consider doing x. That suggests the programmer should take a moment to think of alternatives before continuing.

The current message regarding mutable variables seems quite direct, as if it might be the only solution. Perhaps in some cases it will be, but encouraging use of immutable variables is probably - generally - a good thing.

One drawback with this suggestion would be that it is less concise. That means slightly more overhead as people read and understand the message.

@jayaddison jayaddison added 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. labels Apr 12, 2021
@Rustin170506

This comment has been minimized.

@jonas-schievink
Copy link
Contributor

Turning x = 6; into let x = 6; is another way to fix the error, so this seems like a reasonable change

@jonas-schievink jonas-schievink added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Apr 13, 2021
@bors bors closed this as completed in c7c59d7 Apr 16, 2021
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 E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants