File tree 3 files changed +16
-4
lines changed
3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 1
1
#![warn(clippy::implicit_saturating_sub)]
2
+ #![allow(clippy::if_same_then_else)]
2
3
3
4
fn main() {
4
5
let a = 12u32;
5
6
let b = 13u32;
7
+ let c = 8u32;
6
8
7
9
let result = a.saturating_sub(b);
8
10
//~^ ERROR: manual arithmetic check found
@@ -13,4 +15,10 @@ fn main() {
13
15
//~^ ERROR: manual arithmetic check found
14
16
let result = a.saturating_sub(b);
15
17
//~^ 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 };
16
24
}
Original file line number Diff line number Diff line change 1
1
#![ warn( clippy:: implicit_saturating_sub) ]
2
+ #![ allow( clippy:: if_same_then_else) ]
2
3
3
4
fn main ( ) {
4
5
let a = 12u32 ;
@@ -17,4 +18,7 @@ fn main() {
17
18
18
19
// Should not warn!
19
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 } ;
20
24
}
Original file line number Diff line number Diff line change 1
1
error: manual arithmetic check found
2
- --> tests/ui/manual_arithmetic_check.rs:7 :18
2
+ --> tests/ui/manual_arithmetic_check.rs:9 :18
3
3
|
4
4
LL | let result = if a > b { a - b } else { 0 };
5
5
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
@@ -8,19 +8,19 @@ LL | let result = if a > b { a - b } else { 0 };
8
8
= help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]`
9
9
10
10
error: manual arithmetic check found
11
- --> tests/ui/manual_arithmetic_check.rs:9 :18
11
+ --> tests/ui/manual_arithmetic_check.rs:11 :18
12
12
|
13
13
LL | let result = if b < a { a - b } else { 0 };
14
14
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
15
15
16
16
error: manual arithmetic check found
17
- --> tests/ui/manual_arithmetic_check.rs:12 :18
17
+ --> tests/ui/manual_arithmetic_check.rs:14 :18
18
18
|
19
19
LL | let result = if a < b { 0 } else { a - b };
20
20
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
21
21
22
22
error: manual arithmetic check found
23
- --> tests/ui/manual_arithmetic_check.rs:14 :18
23
+ --> tests/ui/manual_arithmetic_check.rs:16 :18
24
24
|
25
25
LL | let result = if b > a { 0 } else { a - b };
26
26
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a.saturating_sub(b)`
You can’t perform that action at this time.
0 commit comments