Auto merge of #4803 - tomprogrammer:issue-4732, r=phansch
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. changelog: Fix false positive in `explicit_counter_loop` Fixes #4732
This commit is contained in:
commit
2646b108d5
@ -2194,8 +2194,9 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
}
|
||||
walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||
NestedVisitorMap::None
|
||||
NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,3 +132,16 @@ pub fn test() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 New Issue
Block a user