Skip to content

Commit a550133

Browse files
committed
Fix false positive of implicit_saturating_sub with else clause
Fixes rust-lang#7831
1 parent d50cfd2 commit a550133

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
4343
return;
4444
}
4545
if_chain! {
46-
if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr);
46+
if let Some(higher::If { cond, then, r#else: None }) = higher::If::hir(expr);
4747

4848
// Check if the conditional expression is a binary operation
4949
if let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind;

tests/ui/implicit_saturating_sub.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,12 @@ fn main() {
157157
if i_64 != 0 {
158158
i_64 -= 1;
159159
}
160+
161+
// issue #7831
162+
// No Lint
163+
if u_32 > 0 {
164+
u_32 -= 1;
165+
} else {
166+
println!("side effect");
167+
}
160168
}

tests/ui/implicit_saturating_sub.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,12 @@ fn main() {
203203
if i_64 != 0 {
204204
i_64 -= 1;
205205
}
206+
207+
// issue #7831
208+
// No Lint
209+
if u_32 > 0 {
210+
u_32 -= 1;
211+
} else {
212+
println!("side effect");
213+
}
206214
}

0 commit comments

Comments
 (0)