RS.CLIPPY.CAST_ABS_TO_UNSIGNED
Casting the result of `abs()` to an unsigned integer can panic
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: cast_abs_to_unsigned. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usage of the abs() method that cast the result to unsigned.
Why is this bad?
The unsigned_abs() method avoids panic when called on the MIN value.
Example
let x: i32 = -42;
let y: u32 = x.abs() as u32;
Use instead:
let x: i32 = -42;
let y: u32 = x.unsigned_abs();
Configuration
-
msrv: The minimum rust version that the project supports. Defaults to therust-versionfield inCargo.toml(default:
current version)