2024-07-19 07:51:56 -05:00
|
|
|
#![warn(clippy::implicit_saturating_sub, clippy::inverted_saturating_sub)]
|
2024-03-19 11:00:31 -05:00
|
|
|
#![allow(clippy::if_same_then_else)]
|
2024-03-19 10:59:08 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = 12u32;
|
|
|
|
let b = 13u32;
|
2024-03-19 11:00:31 -05:00
|
|
|
let c = 8u32;
|
2024-03-19 10:59:08 -05:00
|
|
|
|
2024-10-10 12:10:04 -05:00
|
|
|
let result = if a > b { a - b } else { a.saturating_sub(b) };
|
2024-03-19 10:59:08 -05:00
|
|
|
//~^ ERROR: manual arithmetic check found
|
2024-10-10 12:10:04 -05:00
|
|
|
let result = if b < a { a - b } else { a.saturating_sub(b) };
|
2024-03-19 10:59:08 -05:00
|
|
|
//~^ ERROR: manual arithmetic check found
|
|
|
|
|
2024-10-10 12:10:04 -05:00
|
|
|
let result = if a < b { a.saturating_sub(b) } else { a - b };
|
2024-03-19 10:59:08 -05:00
|
|
|
//~^ ERROR: manual arithmetic check found
|
2024-10-10 12:10:04 -05:00
|
|
|
let result = if b > a { a.saturating_sub(b) } else { a - b };
|
2024-03-19 10:59:08 -05:00
|
|
|
//~^ ERROR: manual arithmetic check found
|
2024-03-19 11:00:31 -05: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 10:59:08 -05:00
|
|
|
}
|