-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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.
lolbinarycat
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.