File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 11#![warn(clippy::implicit_saturating_sub)]
2+ #![allow(clippy::if_same_then_else)]
23
34fn main() {
45 let a = 12u32;
56 let b = 13u32;
7+ let c = 8u32;
68
79 let result = a.saturating_sub(b);
810 //~^ ERROR: manual arithmetic check found
@@ -13,4 +15,10 @@ fn main() {
1315 //~^ ERROR: manual arithmetic check found
1416 let result = a.saturating_sub(b);
1517 //~^ ERROR: manual arithmetic check found
18+
19+ // Should not warn!
20+ let result = if a > b { a - b } else { a - c };
21+
22+ // Just to check it won't break clippy.
23+ let result = if b > a { 0 } else { 0 };
1624}
Original file line number Diff line number Diff line change 11#![ warn( clippy:: implicit_saturating_sub) ]
2+ #![ allow( clippy:: if_same_then_else) ]
23
34fn main ( ) {
45 let a = 12u32 ;
@@ -17,4 +18,7 @@ fn main() {
1718
1819 // Should not warn!
1920 let result = if a > b { a - b } else { a - c } ;
21+
22+ // Just to check it won't break clippy.
23+ let result = if b > a { 0 } else { 0 } ;
2024}
Original file line number Diff line number Diff line change 11error: manual arithmetic check found
2- --> tests/ui/manual_arithmetic_check.rs:7 :18
2+ --> tests/ui/manual_arithmetic_check.rs:9 :18
33 |
44LL | let result = if a > b { a - b } else { 0 };
55 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
@@ -8,19 +8,19 @@ LL | let result = if a > b { a - b } else { 0 };
88 = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]`
99
1010error: manual arithmetic check found
11- --> tests/ui/manual_arithmetic_check.rs:9 :18
11+ --> tests/ui/manual_arithmetic_check.rs:11 :18
1212 |
1313LL | let result = if b < a { a - b } else { 0 };
1414 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
1515
1616error: manual arithmetic check found
17- --> tests/ui/manual_arithmetic_check.rs:12 :18
17+ --> tests/ui/manual_arithmetic_check.rs:14 :18
1818 |
1919LL | let result = if a < b { 0 } else { a - b };
2020 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
2121
2222error: manual arithmetic check found
23- --> tests/ui/manual_arithmetic_check.rs:14 :18
23+ --> tests/ui/manual_arithmetic_check.rs:16 :18
2424 |
2525LL | let result = if b > a { 0 } else { a - b };
2626 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
You can’t perform that action at this time.
0 commit comments