rust/tests/ui/unnecessary_min_or_max.fixed
2024-06-20 13:57:16 +00:00

68 lines
1.4 KiB
Rust

//@aux-build:external_consts.rs
#![allow(unused)]
#![warn(clippy::unnecessary_min_or_max)]
#![allow(clippy::identity_op)]
extern crate external_consts;
const X: i32 = 1;
fn main() {
// Both are Literals
let _ = (-6_i32);
let _ = 9;
let _ = 6;
let _ = 9_u32;
let _ = 6;
let _ = 7_u8;
let x: u32 = 42;
// unsigned with zero
let _ = 0;
let _ = x;
let _ = 0_u32;
let _ = x;
let x: i32 = 42;
// signed MIN
let _ = i32::MIN;
let _ = x;
let _ = i32::MIN;
let _ = x;
let _ = i32::MIN - 0;
let _ = x;
let _ = i32::MIN - 0;
// The below cases shouldn't be lint
let mut min = u32::MAX;
for _ in 0..1000 {
min = min.min(random_u32());
}
let _ = 2.min(external_consts::MAGIC_NUMBER);
let _ = 2.max(external_consts::MAGIC_NUMBER);
let _ = external_consts::MAGIC_NUMBER.min(2);
let _ = external_consts::MAGIC_NUMBER.max(2);
let _ = X.min(external_consts::MAGIC_NUMBER);
let _ = X.max(external_consts::MAGIC_NUMBER);
let _ = external_consts::MAGIC_NUMBER.min(X);
let _ = external_consts::MAGIC_NUMBER.max(X);
let _ = X.max(12);
let _ = X.min(12);
let _ = 12.min(X);
let _ = 12.max(X);
let _ = (X + 1).max(12);
let _ = (X + 1).min(12);
let _ = 12.min(X - 1);
let _ = 12.max(X - 1);
}
fn random_u32() -> u32 {
// random number generator
0
}