Closed
Description
What it does
Right now, the lint checks for patterns with checked_add
and unwrap_or
. It could perhaps be extended (or it could be a new lint which covers manual wrapping or checked arithmetic as well) to also check for other patterns that don't use checked_add
. For example with unsigned integers:
let result = if a > b { a - b } else { 0 };
which could be rewritten as:
let result = a.saturating_sub(b);
Lint Name
manual_saturating_arithmetic
Category
complexity
Advantage
- simpler code
- more coverage over the original lint
Drawbacks
- more complex checking
Example
let result = if a > b { a - b } else { 0 };
Could be written as:
let result = a.saturating_sub(b);