@@ -437,8 +437,10 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
437437 fn pop_head_constructor ( & self , ctor_wild_subpatterns : & Fields < ' p , ' tcx > ) -> PatStack < ' p , ' tcx > {
438438 // We pop the head pattern and push the new fields extracted from the arguments of
439439 // `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)
442444 }
443445}
444446
@@ -1252,6 +1254,18 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
12521254 pats. into_iter ( )
12531255 }
12541256
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+
12551269 /// Overrides some of the fields with the provided patterns. Exactly like
12561270 /// `replace_fields_indexed`, except that it takes `FieldPat`s as input.
12571271 fn replace_with_fieldpats (
@@ -1358,21 +1372,6 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
13581372 _ => self . clone ( ) ,
13591373 }
13601374 }
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- }
13761375}
13771376
13781377#[ derive( Clone , Debug ) ]
0 commit comments