Closed
Description
Let's say I wrote this critical piece of code:
fn main() {
let mut i = 42;
}
rustc gives me the following output:
warning: unused variable: `i`
--> src/main.rs:2:9
|
2 | let mut i = 42;
| ^^^^^ help: consider using `_i` instead
|
= note: #[warn(unused_variables)] on by default
warning: variable does not need to be mutable
--> src/main.rs:2:9
|
2 | let mut i = 42;
| ----^
| |
| help: remove this `mut`
|
= note: #[warn(unused_mut)] on by default
Which is correct -- except for one little detail. Which is crucial, if you are not just any developer but actually rustfix.
You see, the mut
in mut i
is highlighted, but the replacement is just for the binding name, not the mutability. (Why not the mutability? Because the mutability is covered by the next lint we trigger, unused_mut
.) And rustfix will rightfully complain if we try to replace parts of the code that we have already replaced.
tl;dr We need to change the span in unused_variables
to only cover the i