Skip to content

Commit b2d5b89

Browse files
committed
Check if it's after the loop earlier
1 parent 116f30d commit b2d5b89

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clippy_lints/src/loops.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,11 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
22502250

22512251
// If node is the desired variable, see how it's used
22522252
if var_def_id(self.cx, expr) == Some(self.var_id) {
2253+
if self.past_loop {
2254+
self.state = VarState::DontWarn;
2255+
return;
2256+
}
2257+
22532258
if let Some(parent) = get_parent_expr(self.cx, expr) {
22542259
match parent.kind {
22552260
ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => {
@@ -2269,10 +2274,6 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
22692274
}
22702275
}
22712276

2272-
if self.past_loop {
2273-
self.state = VarState::DontWarn;
2274-
return;
2275-
}
22762277
walk_expr(self, expr);
22772278
} else if !self.past_loop && is_loop(expr) {
22782279
self.state = VarState::DontWarn;

0 commit comments

Comments
 (0)