@@ -437,8 +437,10 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
437
437
fn pop_head_constructor ( & self , ctor_wild_subpatterns : & Fields < ' p , ' tcx > ) -> PatStack < ' p , ' tcx > {
438
438
// We pop the head pattern and push the new fields extracted from the arguments of
439
439
// `self.head()`.
440
- let new_fields = ctor_wild_subpatterns. replace_with_pattern_arguments ( self . head ( ) ) ;
441
- new_fields. push_on_patstack ( & self . pats [ 1 ..] )
440
+ let mut new_fields =
441
+ ctor_wild_subpatterns. replace_with_pattern_arguments ( self . head ( ) ) . filtered_patterns ( ) ;
442
+ new_fields. extend_from_slice ( & self . pats [ 1 ..] ) ;
443
+ PatStack :: from_vec ( new_fields)
442
444
}
443
445
}
444
446
@@ -1252,6 +1254,18 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1252
1254
pats. into_iter ( )
1253
1255
}
1254
1256
1257
+ /// Returns the filtered list of patterns, not including hidden fields.
1258
+ fn filtered_patterns ( self ) -> SmallVec < [ & ' p Pat < ' tcx > ; 2 ] > {
1259
+ match self {
1260
+ Fields :: Slice ( pats) => pats. iter ( ) . collect ( ) ,
1261
+ Fields :: Vec ( pats) => pats,
1262
+ Fields :: Filtered { fields, .. } => {
1263
+ // We skip hidden fields here
1264
+ fields. into_iter ( ) . filter_map ( |p| p. kept ( ) ) . collect ( )
1265
+ }
1266
+ }
1267
+ }
1268
+
1255
1269
/// Overrides some of the fields with the provided patterns. Exactly like
1256
1270
/// `replace_fields_indexed`, except that it takes `FieldPat`s as input.
1257
1271
fn replace_with_fieldpats (
@@ -1358,21 +1372,6 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
1358
1372
_ => self . clone ( ) ,
1359
1373
}
1360
1374
}
1361
-
1362
- fn push_on_patstack ( self , stack : & [ & ' p Pat < ' tcx > ] ) -> PatStack < ' p , ' tcx > {
1363
- let pats: SmallVec < _ > = match self {
1364
- Fields :: Slice ( pats) => pats. iter ( ) . chain ( stack. iter ( ) . copied ( ) ) . collect ( ) ,
1365
- Fields :: Vec ( mut pats) => {
1366
- pats. extend_from_slice ( stack) ;
1367
- pats
1368
- }
1369
- Fields :: Filtered { fields, .. } => {
1370
- // We skip hidden fields here
1371
- fields. into_iter ( ) . filter_map ( |p| p. kept ( ) ) . chain ( stack. iter ( ) . copied ( ) ) . collect ( )
1372
- }
1373
- } ;
1374
- PatStack :: from_vec ( pats)
1375
- }
1376
1375
}
1377
1376
1378
1377
#[ derive( Clone , Debug ) ]
0 commit comments