@@ -1110,7 +1110,7 @@ fn has_mutable_variables<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr)
11101110struct ForPatternVisitor < ' a , ' tcx > {
11111111 found_pattern : bool ,
11121112 // Pattern that we are searching for
1113- for_pattern_hir_id : HirId ,
1113+ for_pattern : & ' a rustc :: hir :: Pat ,
11141114 cx : & ' a LateContext < ' a , ' tcx > ,
11151115}
11161116
@@ -1138,9 +1138,17 @@ impl<'a, 'tcx> Visitor<'tcx> for ForPatternVisitor<'a, 'tcx> {
11381138 // expr assuming it is a Path
11391139 if let Some ( hir_id) = var_def_id ( self . cx , & expr) {
11401140 // Pattern is found
1141- if hir_id == self . for_pattern_hir_id {
1141+ if hir_id == self . for_pattern . hir_id {
11421142 self . found_pattern = true ;
11431143 }
1144+ // If the for loop pattern is a tuple, determine whether the current
1145+ // expr is inside that tuple pattern
1146+ if let PatKind :: Tuple ( pat_list, _) = & self . for_pattern . kind {
1147+ let hir_id_list: Vec < HirId > = pat_list. iter ( ) . map ( |p| p. hir_id ) . collect ( ) ;
1148+ if hir_id_list. contains ( & hir_id) {
1149+ self . found_pattern = true ;
1150+ }
1151+ }
11441152 }
11451153 } ,
11461154 }
@@ -1151,9 +1159,17 @@ impl<'a, 'tcx> Visitor<'tcx> for ForPatternVisitor<'a, 'tcx> {
11511159 if_chain ! {
11521160 if let rustc:: hir:: QPath :: Resolved ( _, path) = qpath;
11531161 if let rustc:: hir:: def:: Res :: Local ( hir_id) = & path. res;
1154- if * hir_id == self . for_pattern_hir_id;
11551162 then {
1156- self . found_pattern = true ;
1163+ if * hir_id == self . for_pattern. hir_id{
1164+ self . found_pattern = true ;
1165+ }
1166+
1167+ if let PatKind :: Tuple ( pat_list, _) = & self . for_pattern. kind {
1168+ let hir_id_list: Vec <HirId > = pat_list. iter( ) . map( |p| p. hir_id) . collect( ) ;
1169+ if hir_id_list. contains( & hir_id) {
1170+ self . found_pattern = true ;
1171+ }
1172+ }
11571173 }
11581174 }
11591175 }
@@ -1255,7 +1271,7 @@ fn detect_same_item_push<'a, 'tcx>(
12551271 // does not contain the for loop pattern
12561272 let mut for_pat_visitor = ForPatternVisitor {
12571273 found_pattern : false ,
1258- for_pattern_hir_id : pat. hir_id ,
1274+ for_pattern : pat,
12591275 cx,
12601276 } ;
12611277 intravisit:: walk_expr ( & mut for_pat_visitor, pushed_item) ;
0 commit comments