This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +29
-10
lines changed Expand file tree Collapse file tree 5 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -184,18 +184,18 @@ fn main() {
184
184
let mut m = Mock;
185
185
let mut u_32 = 3000;
186
186
let a = 200;
187
- let mut _b = 8;
187
+ let mut b = 8;
188
188
189
189
if m != 0 {
190
190
m -= 1;
191
191
}
192
192
193
193
if a > 0 {
194
- _b -= 1;
194
+ b -= 1;
195
195
}
196
196
197
197
if 0 > a {
198
- _b -= 1;
198
+ b -= 1;
199
199
}
200
200
201
201
if u_32 > 0 {
@@ -214,4 +214,11 @@ fn main() {
214
214
} else if u_32 > 0 {
215
215
u_32 -= 1;
216
216
}
217
+
218
+ let result = if a < b {
219
+ println!("we shouldn't remove this");
220
+ 0
221
+ } else {
222
+ a - b
223
+ };
217
224
}
Original file line number Diff line number Diff line change @@ -230,18 +230,18 @@ fn main() {
230
230
let mut m = Mock ;
231
231
let mut u_32 = 3000 ;
232
232
let a = 200 ;
233
- let mut _b = 8 ;
233
+ let mut b = 8 ;
234
234
235
235
if m != 0 {
236
236
m -= 1 ;
237
237
}
238
238
239
239
if a > 0 {
240
- _b -= 1 ;
240
+ b -= 1 ;
241
241
}
242
242
243
243
if 0 > a {
244
- _b -= 1 ;
244
+ b -= 1 ;
245
245
}
246
246
247
247
if u_32 > 0 {
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