Skip to content

explicit_counter_loop fix #3308 false positive #3310

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

Merged
merged 1 commit into from
Oct 13, 2018
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
5 changes: 1 addition & 4 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions tests/ui/for_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}