Skip to content

Commit

Permalink
Fix false positive of implicit_saturating_sub with else clause
Browse files Browse the repository at this point in the history
Fixes #7831
  • Loading branch information
narpfel committed Oct 17, 2021
1 parent d50cfd2 commit a550133
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clippy_lints/src/implicit_saturating_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
return;
}
if_chain! {
if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr);
if let Some(higher::If { cond, then, r#else: None }) = higher::If::hir(expr);

// Check if the conditional expression is a binary operation
if let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind;
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/implicit_saturating_sub.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,12 @@ fn main() {
if i_64 != 0 {
i_64 -= 1;
}

// issue #7831
// No Lint
if u_32 > 0 {
u_32 -= 1;
} else {
println!("side effect");
}
}
8 changes: 8 additions & 0 deletions tests/ui/implicit_saturating_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,12 @@ fn main() {
if i_64 != 0 {
i_64 -= 1;
}

// issue #7831
// No Lint
if u_32 > 0 {
u_32 -= 1;
} else {
println!("side effect");
}
}

0 comments on commit a550133

Please sign in to comment.