@@ -150,7 +150,8 @@ impl LateLintPass for LoopsPass {
150
150
for ( id, _) in visitor. states . iter ( ) . filter ( |& ( _, v) | * v == VarState :: IncrOnce ) {
151
151
let mut visitor2 = InitializeVisitor { cx : cx, end_expr : expr, var_id : id. clone ( ) ,
152
152
state : VarState :: IncrOnce , name : None ,
153
- depth : 0 , done : false } ;
153
+ depth : 0 ,
154
+ past_loop : false } ;
154
155
walk_block ( & mut visitor2, block) ;
155
156
156
157
if visitor2. state == VarState :: Warn {
@@ -502,7 +503,7 @@ struct InitializeVisitor<'v, 't: 'v> {
502
503
state : VarState ,
503
504
name : Option < Name > ,
504
505
depth : u32 , // depth of conditional expressions
505
- done : bool
506
+ past_loop : bool
506
507
}
507
508
508
509
impl < ' v , ' t > Visitor < ' v > for InitializeVisitor < ' v , ' t > {
@@ -530,12 +531,16 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
530
531
}
531
532
532
533
fn visit_expr ( & mut self , expr : & ' v Expr ) {
533
- if self . state == VarState :: DontWarn || expr == self . end_expr {
534
- self . done = true ;
534
+ if self . state == VarState :: DontWarn {
535
+ return ;
536
+ }
537
+ if expr == self . end_expr {
538
+ self . past_loop = true ;
539
+ return ;
535
540
}
536
541
// No need to visit expressions before the variable is
537
- // declared or after we've rejected it.
538
- if self . state == VarState :: IncrOnce || self . done {
542
+ // declared
543
+ if self . state == VarState :: IncrOnce {
539
544
return ;
540
545
}
541
546
@@ -556,11 +561,15 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
556
561
_ => ( )
557
562
}
558
563
}
564
+
565
+ if self . past_loop {
566
+ self . state = VarState :: DontWarn ;
567
+ return ;
568
+ }
559
569
}
560
570
// If there are other loops between the declaration and the target loop, give up
561
- else if is_loop ( expr) {
571
+ else if ! self . past_loop && is_loop ( expr) {
562
572
self . state = VarState :: DontWarn ;
563
- self . done = true ;
564
573
return ;
565
574
}
566
575
// Keep track of whether we're inside a conditional expression
0 commit comments