@@ -588,24 +588,23 @@ fn check_for_loop_explicit_counter(cx: &LateContext, arg: &Expr, body: &Expr, ex
588
588
}
589
589
}
590
590
591
- // Check for the FOR_KV_MAP lint.
591
+ /// Check for the FOR_KV_MAP lint.
592
592
fn check_for_loop_over_map_kv ( cx : & LateContext , pat : & Pat , arg : & Expr , body : & Expr , expr : & Expr ) {
593
593
if let PatKind :: Tup ( ref pat) = pat. node {
594
594
if pat. len ( ) == 2 {
595
-
596
595
let ( pat_span, kind) = match ( & pat[ 0 ] . node , & pat[ 1 ] . node ) {
597
596
( key, _) if pat_is_wild ( key, body) => ( & pat[ 1 ] . span , "values" ) ,
598
597
( _, value) if pat_is_wild ( value, body) => ( & pat[ 0 ] . span , "keys" ) ,
599
598
_ => return ,
600
599
} ;
601
600
602
- let ty = walk_ptrs_ty ( cx. tcx . expr_ty ( arg) ) ;
603
- let arg_span = if let ExprAddrOf ( _, ref expr) = arg. node {
604
- expr. span
605
- } else {
606
- arg. span
601
+ let arg_span = match arg. node {
602
+ ExprAddrOf ( MutImmutable , ref expr) => expr. span ,
603
+ ExprAddrOf ( MutMutable , _) => return , // for _ in &mut _, there is no {values,keys}_mut method
604
+ _ => arg. span ,
607
605
} ;
608
606
607
+ let ty = walk_ptrs_ty ( cx. tcx . expr_ty ( arg) ) ;
609
608
if match_type ( cx, ty, & HASHMAP_PATH ) || match_type ( cx, ty, & BTREEMAP_PATH ) {
610
609
span_lint_and_then ( cx,
611
610
FOR_KV_MAP ,
@@ -625,7 +624,7 @@ fn check_for_loop_over_map_kv(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Ex
625
624
626
625
}
627
626
628
- // Return true if the pattern is a `PatWild` or an ident prefixed with '_'.
627
+ /// Return true if the pattern is a `PatWild` or an ident prefixed with '_'.
629
628
fn pat_is_wild ( pat : & PatKind , body : & Expr ) -> bool {
630
629
match * pat {
631
630
PatKind :: Wild => true ,
@@ -845,7 +844,7 @@ enum VarState {
845
844
DontWarn ,
846
845
}
847
846
848
- // Scan a for loop for variables that are incremented exactly once.
847
+ /// Scan a for loop for variables that are incremented exactly once.
849
848
struct IncrementVisitor < ' v , ' t : ' v > {
850
849
cx : & ' v LateContext < ' v , ' t > , // context reference
851
850
states : HashMap < NodeId , VarState > , // incremented variables
@@ -897,7 +896,7 @@ impl<'v, 't> Visitor<'v> for IncrementVisitor<'v, 't> {
897
896
}
898
897
}
899
898
900
- // Check whether a variable is initialized to zero at the start of a loop.
899
+ /// Check whether a variable is initialized to zero at the start of a loop.
901
900
struct InitializeVisitor < ' v , ' t : ' v > {
902
901
cx : & ' v LateContext < ' v , ' t > , // context reference
903
902
end_expr : & ' v Expr , // the for loop. Stop scanning here.
0 commit comments