Skip to content

Commit 7fb267b

Browse files
committed
Fixed edge case of iXX compared with 0
1 parent 9cd43ae commit 7fb267b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clippy_lints/src/implicit_saturating_sub.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitSaturatingSub {
8888
ExprKind::Lit(ref cond_lit) => {
8989
// Check if the constant is zero
9090
if let LitKind::Int(0, _) = cond_lit.node {
91-
print_lint_and_sugg(cx, &var_name, expr);
91+
if cx.tables.expr_ty(cond_left).is_signed() {
92+
return;
93+
} else {
94+
print_lint_and_sugg(cx, &var_name, expr);
95+
}
9296
} else {
9397
return;
9498
}

tests/ui/implicit_saturating_sub.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,9 @@ fn main() {
146146
if i_64 > i64::min_value() {
147147
i_64 -= 1;
148148
}
149+
150+
// No Lint
151+
if i_64 > 0 {
152+
i_64 -= 1;
153+
}
149154
}

0 commit comments

Comments
 (0)