RS.CLIPPY.INVERTED_SATURATING_SUB
Check if a variable is smaller than another one and still subtract from it even if smaller
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: inverted_saturating_sub. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for comparisons between integers, followed by subtracting the greater value from the lower one.
Why is this bad?
This could result in an underflow and is most likely not what the user wants. If this was
intended to be a saturated subtraction, consider using the saturating_sub method directly.
Example
let a = 12u32;
let b = 13u32;
let result = if a > b { b - a } else { 0 };
Use instead:
let a = 12u32;
let b = 13u32;
let result = a.saturating_sub(b);