2022-04-07 12:39:59 -05:00
|
|
|
// run-rustfix
|
2022-10-23 08:18:45 -05:00
|
|
|
|
|
|
|
#![feature(custom_inner_attributes)]
|
2022-04-07 12:39:59 -05:00
|
|
|
#![warn(clippy::cast_abs_to_unsigned)]
|
2022-10-23 08:18:45 -05:00
|
|
|
#![allow(clippy::uninlined_format_args, unused)]
|
2022-04-07 12:39:59 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x: i32 = -42;
|
|
|
|
let y: u32 = x.unsigned_abs();
|
|
|
|
println!("The absolute value of {} is {}", x, y);
|
2022-06-04 06:34:07 -05:00
|
|
|
|
|
|
|
let a: i32 = -3;
|
|
|
|
let _: usize = a.unsigned_abs() as usize;
|
|
|
|
let _: usize = a.unsigned_abs() as _;
|
|
|
|
let _ = a.unsigned_abs() as usize;
|
|
|
|
|
|
|
|
let a: i64 = -3;
|
|
|
|
let _ = a.unsigned_abs() as usize;
|
|
|
|
let _ = a.unsigned_abs() as u8;
|
|
|
|
let _ = a.unsigned_abs() as u16;
|
|
|
|
let _ = a.unsigned_abs() as u32;
|
|
|
|
let _ = a.unsigned_abs();
|
|
|
|
let _ = a.unsigned_abs() as u128;
|
|
|
|
|
|
|
|
let a: isize = -3;
|
|
|
|
let _ = a.unsigned_abs();
|
|
|
|
let _ = a.unsigned_abs() as u8;
|
|
|
|
let _ = a.unsigned_abs() as u16;
|
|
|
|
let _ = a.unsigned_abs() as u32;
|
|
|
|
let _ = a.unsigned_abs() as u64;
|
|
|
|
let _ = a.unsigned_abs() as u128;
|
2022-08-11 12:42:16 -05:00
|
|
|
|
|
|
|
let _ = (x as i64 - y as i64).unsigned_abs() as u32;
|
2022-04-07 12:39:59 -05:00
|
|
|
}
|
2022-10-23 08:18:45 -05:00
|
|
|
|
|
|
|
fn msrv_1_50() {
|
|
|
|
#![clippy::msrv = "1.50"]
|
|
|
|
|
|
|
|
let x: i32 = 10;
|
|
|
|
assert_eq!(10u32, x.abs() as u32);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn msrv_1_51() {
|
|
|
|
#![clippy::msrv = "1.51"]
|
|
|
|
|
|
|
|
let x: i32 = 10;
|
|
|
|
assert_eq!(10u32, x.unsigned_abs());
|
|
|
|
}
|