diff options
| author | Josh Mcguigan <joshmcg88@gmail.com> | 2018-10-13 06:57:52 -0700 |
|---|---|---|
| committer | Josh Mcguigan <joshmcg88@gmail.com> | 2018-10-13 06:57:52 -0700 |
| commit | c6f79c7ba0dcefaae7e96912a066ecbf4f63e8ca (patch) | |
| tree | 4725453997ac14f514ab306f9a16fc4026169a4d | |
| parent | 8b12eee1120daaf8894a095904d814b52cdabc49 (diff) | |
| download | rust-c6f79c7ba0dcefaae7e96912a066ecbf4f63e8ca.tar.gz rust-c6f79c7ba0dcefaae7e96912a066ecbf4f63e8ca.zip | |
explicit_counter_loop fix #3308 false positive
| -rw-r--r-- | clippy_lints/src/loops.rs | 5 | ||||
| -rw-r--r-- | tests/ui/for_loop.rs | 35 |
2 files changed, 36 insertions, 4 deletions
diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index b807e4fb9e1..064a8d5229d 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1952,10 +1952,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> { _ => (), } } - } else if is_loop(expr) { - walk_expr(self, expr); - return; - } else if is_conditional(expr) { + } else if is_loop(expr) || is_conditional(expr) { self.depth += 1; walk_expr(self, expr); self.depth -= 1; diff --git a/tests/ui/for_loop.rs b/tests/ui/for_loop.rs index bdb6b56e0bb..89c452f44df 100644 --- a/tests/ui/for_loop.rs +++ b/tests/ui/for_loop.rs @@ -646,3 +646,38 @@ mod issue_1219 { } } } + +mod issue_3308 { + #[warn(clippy::explicit_counter_loop)] + pub fn test() { + // should not trigger the lint because the count is incremented multiple times + let mut skips = 0; + let erasures = vec![]; + for i in 0..10 { + while erasures.contains(&(i + skips)) { + skips += 1; + } + println!("{}", skips); + } + + // should not trigger the lint because the count is incremented multiple times + let mut skips = 0; + for i in 0..10 { + let mut j = 0; + while j < 5 { + skips += 1; + j += 1; + } + println!("{}", skips); + } + + // should not trigger the lint because the count is incremented multiple times + let mut skips = 0; + for i in 0..10 { + for j in 0..5 { + skips += 1; + } + println!("{}", skips); + } + } +} |
