about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-06 17:15:53 +0000
committerbors <bors@rust-lang.org>2024-10-06 17:15:53 +0000
commit1c9e5d0e5caa0ffacda31774d7eca334bf55ce7d (patch)
tree0a962f699f1a452e1744d34ca623d6c515831341
parentf7aaecf3f5b8eba87ac71a4df7479ebb273a2268 (diff)
parentaf6816c5b6a4b2cca1308d52c40543bb845b9d44 (diff)
downloadrust-1c9e5d0e5caa0ffacda31774d7eca334bf55ce7d.tar.gz
rust-1c9e5d0e5caa0ffacda31774d7eca334bf55ce7d.zip
Auto merge of #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
-rw-r--r--clippy_lints/src/loops/infinite_loop.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/clippy_lints/src/loops/infinite_loop.rs b/clippy_lints/src/loops/infinite_loop.rs
index 858e3be5093..64ae0807015 100644
--- a/clippy_lints/src/loops/infinite_loop.rs
+++ b/clippy_lints/src/loops/infinite_loop.rs
@@ -112,7 +112,7 @@ impl<'hir> Visitor<'hir> for LoopVisitor<'hir, '_> {
             ExprKind::Loop(..) => {
                 self.loop_depth += 1;
                 walk_expr(self, ex);
-                self.loop_depth = self.loop_depth.saturating_sub(1);
+                self.loop_depth -= 1;
             },
             _ => {
                 // Calls to a function that never return