Auto merge of #7832 - narpfel:implicit-saturating-sub-false-positive-else, r=giraffate

Fix false positive of `implicit_saturating_sub` with `else` clause

Fixes #7831

changelog: Fix false positive of [`implicit_saturating_sub`] with `else` clause
This commit is contained in:
bors 2021-10-18 00:22:48 +00:00
commit af85240049
3 changed files with 17 additions and 1 deletions

View File

@ -43,7 +43,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
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;

View File

@ -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");
}
}

View File

@ -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");
}
}