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

Inhibit unused_mut variables if unused_variables is also triggered #97074

Open
djc opened this issue May 16, 2022 · 0 comments
Open

Inhibit unused_mut variables if unused_variables is also triggered #97074

djc opened this issue May 16, 2022 · 0 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.

Comments

@djc
Copy link
Contributor

djc commented May 16, 2022

Given the following code:

fn main() {
    let mut s = String::from("a");
}

(Playground.)

The current output is:

warning: unused variable: `s`
 [--> src/main.rs:2:13
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     let mut s = String::from("a");
  |             ^ help: if this is intentional, prefix it with an underscore: `_s`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
 [--> src/main.rs:2:9
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     let mut s = String::from("a");
  |         ----^
  |         |
  |         help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

warning: `playground` (bin "playground") generated 2 warnings
warning: unused variable: `s`
 [--> src/main.rs:2:13
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     let mut s = String::from("a");
  |             ^ help: if this is intentional, prefix it with an underscore: `_s`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable

It's obvious that an unused variable does not need to be declared mutable, and the extra warning puts more cognitive burden on the reader to figure out what's relevant.

Found this on 1.60.0, but also still happens on nightly.

@djc djc 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 May 16, 2022
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant