Skip to content

Commit 1c9e5d0

Browse files
committed
Auto merge of rust-lang#13513 - samueltardieu:push-zvvzytrovulq, r=y21
Style: do not defensively use `saturating_sub()` Using `saturating_sub()` here in code which cannot fail brings a false sense of security. If for any reason a logic error was introduced and caused `self.loop_depth` to reach 0 before being decremented, using `saturating_sub(1)` would silently mask the programming error instead of panicking loudly as it should (at least in dev profile). changelog: none
2 parents f7aaecf + af6816c commit 1c9e5d0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clippy_lints/src/loops/infinite_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'hir> Visitor<'hir> for LoopVisitor<'hir, '_> {
112112
ExprKind::Loop(..) => {
113113
self.loop_depth += 1;
114114
walk_expr(self, ex);
115-
self.loop_depth = self.loop_depth.saturating_sub(1);
115+
self.loop_depth -= 1;
116116
},
117117
_ => {
118118
// Calls to a function that never return

0 commit comments

Comments
 (0)