
Description
What it does
It detects variables like let _unused = 1;
and suggests deleting that variable because it serves 0% purpose and has no side effects whatsoever. This is different from let _unused_result = function();
which likely has a side effect (unless the function is empty/the function contents have no side effect, maybe that should be detected too? Probably not but I'm not sure).
See also: #7527 (comment)
Categories (optional)
- Kind:
clippy::suspicious
.
It removes unused variables that serve no purpose.
One could argue that there are use cases for this like tests (for rustc
I suppose) or examples merely showing off the ability to declare such variables, but one can of course always turn this lint off and in the most common case the user will actually want to remove this underscored variable with 0% side effects, I believe.
Drawbacks
- The requirement to mute the lint, in very rare cases where the user wants this.
Example
fn main() {
let _i_serve_no_purpose = 1;
}
Could be written as:
fn main() { }
If the variable is used afterwards then of course there should be no lint regardless of whether there is a side effect in the variable declaration itself or not.