Corrected explicit_counter_loop behavior with nested loops
This commit is contained in:
parent
53c262048c
commit
9168746c38
@ -1942,8 +1942,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
} else if is_loop(expr) {
|
||||
self.states.clear();
|
||||
self.done = true;
|
||||
walk_expr(self, expr);
|
||||
return;
|
||||
} else if is_conditional(expr) {
|
||||
self.depth += 1;
|
||||
|
@ -612,5 +612,27 @@ mod issue_1219 {
|
||||
}
|
||||
println!("{}", count);
|
||||
}
|
||||
|
||||
// should trigger the lint because the count is not conditional
|
||||
let text = "banana";
|
||||
let mut count = 0;
|
||||
for ch in text.chars() {
|
||||
count += 1;
|
||||
for i in 0..2 {
|
||||
let _ = 123;
|
||||
}
|
||||
println!("{}", count);
|
||||
}
|
||||
|
||||
// should not trigger the lint because the count is incremented multiple times
|
||||
let text = "banana";
|
||||
let mut count = 0;
|
||||
for ch in text.chars() {
|
||||
count += 1;
|
||||
for i in 0..2 {
|
||||
count += 1;
|
||||
}
|
||||
println!("{}", count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -493,5 +493,11 @@ error: the variable `count` is used as a loop counter. Consider using `for (coun
|
||||
608 | for ch in text.chars() {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 60 previous errors
|
||||
error: the variable `count` is used as a loop counter. Consider using `for (count, item) in text.chars().enumerate()` or similar iterators
|
||||
--> $DIR/for_loop.rs:619:19
|
||||
|
|
||||
619 | for ch in text.chars() {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 61 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user