@@ -1110,7 +1110,7 @@ fn has_mutable_variables<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr)
1110
1110
struct ForPatternVisitor < ' a , ' tcx > {
1111
1111
found_pattern : bool ,
1112
1112
// Pattern that we are searching for
1113
- for_pattern_hir_id : HirId ,
1113
+ for_pattern : & ' a rustc :: hir :: Pat ,
1114
1114
cx : & ' a LateContext < ' a , ' tcx > ,
1115
1115
}
1116
1116
@@ -1138,9 +1138,17 @@ impl<'a, 'tcx> Visitor<'tcx> for ForPatternVisitor<'a, 'tcx> {
1138
1138
// expr assuming it is a Path
1139
1139
if let Some ( hir_id) = var_def_id ( self . cx , & expr) {
1140
1140
// Pattern is found
1141
- if hir_id == self . for_pattern_hir_id {
1141
+ if hir_id == self . for_pattern . hir_id {
1142
1142
self . found_pattern = true ;
1143
1143
}
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
+ }
1144
1152
}
1145
1153
} ,
1146
1154
}
@@ -1151,9 +1159,17 @@ impl<'a, 'tcx> Visitor<'tcx> for ForPatternVisitor<'a, 'tcx> {
1151
1159
if_chain ! {
1152
1160
if let rustc:: hir:: QPath :: Resolved ( _, path) = qpath;
1153
1161
if let rustc:: hir:: def:: Res :: Local ( hir_id) = & path. res;
1154
- if * hir_id == self . for_pattern_hir_id;
1155
1162
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
+ }
1157
1173
}
1158
1174
}
1159
1175
}
@@ -1255,7 +1271,7 @@ fn detect_same_item_push<'a, 'tcx>(
1255
1271
// does not contain the for loop pattern
1256
1272
let mut for_pat_visitor = ForPatternVisitor {
1257
1273
found_pattern : false ,
1258
- for_pattern_hir_id : pat. hir_id ,
1274
+ for_pattern : pat,
1259
1275
cx,
1260
1276
} ;
1261
1277
intravisit:: walk_expr ( & mut for_pat_visitor, pushed_item) ;
0 commit comments