Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positive of implicit_saturating_sub with else clause #7832

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}