Skip to content

Immutable variable reassignment help message #84144

Closed
@jayaddison

Description

@jayaddison

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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