Fix false positive of implicit_saturating_sub with else clause

Fixes #7831
This commit is contained in:
Paul Gey 2021-10-17 15:56:59 +02:00
parent d50cfd26e5
commit a550133b8f
3 changed files with 17 additions and 1 deletions

View file

@ -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;

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