mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-17 18:28:40 +00:00
b0edbca0e6
Add a lint to detect cast to unsigned for abs() and suggest unsigned_abs() to avoid panic when called on MIN.
8 lines
180 B
Rust
8 lines
180 B
Rust
// run-rustfix
|
|
#![warn(clippy::cast_abs_to_unsigned)]
|
|
|
|
fn main() {
|
|
let x: i32 = -42;
|
|
let y: u32 = x.unsigned_abs();
|
|
println!("The absolute value of {} is {}", x, y);
|
|
}
|