Description
After having spent a day tracking down this bug, and recalling all the past times the same thing has bitten me, I'd like to propose a lint unused results of arithmetic expressions. Consider the following code:
let mut delta = 0isize;
match foo {
Foo::Add(x) => {
delta += x;
}
Foo::Sub(x) => {
delta - x;
}
}
This code currently compiles with no warnings (given a suitable enum Foo
). However, bugs like these can be extremely hard to track down. They can often be hard to spot, especially when going through methods like saturating_sub
which do not modify self
, but instead return the new result (e.g., delta = delta.saturating_sub(x)
is necessary).
It would be really neat to have a warning about unused arithmetic expressions (ideally one that also handles saturating_sub
). I don't think there are generally cases where not using the result of an arithmetic expression is what the developer intended to do. This also complements the unused_variables
and unused_mut
lints quite nicely.