RS.CLIPPY.MANUAL_ABS_DIFF
Using an if-else pattern instead of `abs_diff`
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: manual_abs_diff. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Detects patterns like if a > b { a - b } else { b - a } and suggests using a.abs_diff(b).
Why is this bad?
Using abs_diff is shorter, more readable, and avoids control flow.
Examples
if a > b {
a - b
} else {
b - a
}
Use instead:
a.abs_diff(b)
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)