Open
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.