mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Fix false positive in explicit_counter_loop lint
When the counter was used in a closure after the loop the lint didn't detect the usage of the counter correctly.
This commit is contained in:
parent
338f5e6801
commit
c88afce6fc
2 changed files with 15 additions and 1 deletions
|
@ -2192,8 +2192,9 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||||
NestedVisitorMap::None
|
NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,3 +132,16 @@ mod issue_1670 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue_4732 {
|
||||||
|
pub fn test() {
|
||||||
|
let slice = &[1, 2, 3];
|
||||||
|
let mut index = 0;
|
||||||
|
|
||||||
|
// should not trigger the lint because the count is used after the loop
|
||||||
|
for _v in slice {
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
let _closure = || println!("index: {}", index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue