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() {
184184 let mut m = Mock;
185185 let mut u_32 = 3000;
186186 let a = 200;
187- let mut _b = 8;
187+ let mut b = 8;
188188
189189 if m != 0 {
190190 m -= 1;
191191 }
192192
193193 if a > 0 {
194- _b -= 1;
194+ b -= 1;
195195 }
196196
197197 if 0 > a {
198- _b -= 1;
198+ b -= 1;
199199 }
200200
201201 if u_32 > 0 {
@@ -214,4 +214,11 @@ fn main() {
214214 } else if u_32 > 0 {
215215 u_32 -= 1;
216216 }
217+
218+ let result = if a < b {
219+ println!("we shouldn't remove this");
220+ 0
221+ } else {
222+ a - b
223+ };
217224}
Original file line number Diff line number Diff line change @@ -230,18 +230,18 @@ fn main() {
230230 let mut m = Mock ;
231231 let mut u_32 = 3000 ;
232232 let a = 200 ;
233- let mut _b = 8 ;
233+ let mut b = 8 ;
234234
235235 if m != 0 {
236236 m -= 1 ;
237237 }
238238
239239 if a > 0 {
240- _b -= 1 ;
240+ b -= 1 ;
241241 }
242242
243243 if 0 > a {
244- _b -= 1 ;
244+ b -= 1 ;
245245 }
246246
247247 if u_32 > 0 {
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