Rust

Rust

Made by DeepSource

Found cast of abs() to unsigned integer type RS-W1131

Bug risk
Minor

Use of the abs() method cast to an unsigned integer type is unidiomatic and can cause a panic if called on the MIN value. The unsigned_abs() method avoids panic or wrong behaviour when called on the MIN value.

Bad practice

fn main() {
    let x: i32 = -42;
    let y = x.abs() as u32; // bad
}

Recommended

fn main() {
    let x: i32 = -42;
    let y = x.unsigned_abs(); // fine
}