Detect useless underscored variables with no side effects #7545
Labels
C-enhancement
Category: Enhancement of lints, like adding more cases or adding help messages
good-first-issue
These issues are a good way to get started with Clippy
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 fromlet _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)
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
Example
Could be written as:
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.
The text was updated successfully, but these errors were encountered: