2024-07-19 12:51:56 +00:00
|
|
|
#![warn(clippy::implicit_saturating_sub, clippy::inverted_saturating_sub)]
|
2024-03-19 16:00:31 +00:00
|
|
|
#![allow(clippy::if_same_then_else)]
|
2024-03-19 15:59:08 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = 12u32;
|
|
|
|
let b = 13u32;
|
2024-03-19 16:00:31 +00:00
|
|
|
let c = 8u32;
|
2024-03-19 15:59:08 +00:00
|
|
|
|
|
|
|
let result = a.saturating_sub(b);
|
|
|
|
//~^ ERROR: manual arithmetic check found
|
|
|
|
let result = a.saturating_sub(b);
|
|
|
|
//~^ ERROR: manual arithmetic check found
|
|
|
|
|
|
|
|
let result = a.saturating_sub(b);
|
|
|
|
//~^ ERROR: manual arithmetic check found
|
|
|
|
let result = a.saturating_sub(b);
|
|
|
|
//~^ ERROR: manual arithmetic check found
|
2024-03-19 16:00:31 +00:00
|
|
|
|
|
|
|
// Should not warn!
|
|
|
|
let result = if a > b { a - b } else { a - c };
|
|
|
|
|
|
|
|
// Just to check it won't break clippy.
|
|
|
|
let result = if b > a { 0 } else { 0 };
|
2024-03-19 15:59:08 +00:00
|
|
|
}
|