Fix #1219 false positive for explicit_counter_loop
This commit is contained in:
parent
ce554267b8
commit
53c262048c
|
@ -1950,6 +1950,9 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
self.depth -= 1;
|
self.depth -= 1;
|
||||||
return;
|
return;
|
||||||
|
} else if let ExprKind::Continue(_) = expr.node {
|
||||||
|
self.done = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -601,5 +601,16 @@ mod issue_1219 {
|
||||||
}
|
}
|
||||||
println!("{}", count);
|
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;
|
||||||
|
if ch == 'a' {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
println!("{}", count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,5 +487,11 @@ error: it looks like you're manually copying between slices
|
||||||
547 | for i in 0..src.len() {
|
547 | for i in 0..src.len() {
|
||||||
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
|
| ^^^^^^^^^^^^ help: try replacing the loop by: `dst[..src.len()].clone_from_slice(&src[..])`
|
||||||
|
|
||||||
error: aborting due to 59 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:608:19
|
||||||
|
|
|
||||||
|
608 | for ch in text.chars() {
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 60 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue