@@ -22,7 +22,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2222 ) {
2323 for fieldpat in subpatterns {
2424 let place = place. clone_project ( PlaceElem :: Field ( fieldpat. field , fieldpat. pattern . ty ) ) ;
25- match_pairs . push ( MatchPairTree :: for_pattern ( place, & fieldpat. pattern , self ) ) ;
25+ MatchPairTree :: for_pattern ( place, & fieldpat. pattern , self , match_pairs ) ;
2626 }
2727 }
2828
@@ -53,11 +53,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5353 ( ( prefix. len ( ) + suffix. len ( ) ) . try_into ( ) . unwrap ( ) , false )
5454 } ;
5555
56- match_pairs . extend ( prefix. iter ( ) . enumerate ( ) . map ( | ( idx , subpattern ) | {
56+ for ( idx , subpattern ) in prefix. iter ( ) . enumerate ( ) {
5757 let elem =
5858 ProjectionElem :: ConstantIndex { offset : idx as u64 , min_length, from_end : false } ;
59- MatchPairTree :: for_pattern ( place. clone_project ( elem) , subpattern, self )
60- } ) ) ;
59+ let place = place. clone_project ( elem) ;
60+ MatchPairTree :: for_pattern ( place, subpattern, self , match_pairs) ;
61+ }
6162
6263 if let Some ( subslice_pat) = opt_slice {
6364 let suffix_len = suffix. len ( ) as u64 ;
@@ -66,19 +67,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6667 to : if exact_size { min_length - suffix_len } else { suffix_len } ,
6768 from_end : !exact_size,
6869 } ) ;
69- match_pairs . push ( MatchPairTree :: for_pattern ( subslice, subslice_pat, self ) ) ;
70+ MatchPairTree :: for_pattern ( subslice, subslice_pat, self , match_pairs ) ;
7071 }
7172
72- match_pairs . extend ( suffix. iter ( ) . rev ( ) . enumerate ( ) . map ( | ( idx , subpattern ) | {
73+ for ( idx , subpattern ) in suffix. iter ( ) . rev ( ) . enumerate ( ) {
7374 let end_offset = ( idx + 1 ) as u64 ;
7475 let elem = ProjectionElem :: ConstantIndex {
7576 offset : if exact_size { min_length - end_offset } else { end_offset } ,
7677 min_length,
7778 from_end : !exact_size,
7879 } ;
7980 let place = place. clone_project ( elem) ;
80- MatchPairTree :: for_pattern ( place, subpattern, self )
81- } ) ) ;
81+ MatchPairTree :: for_pattern ( place, subpattern, self , match_pairs ) ;
82+ }
8283 }
8384}
8485
@@ -89,7 +90,8 @@ impl<'tcx> MatchPairTree<'tcx> {
8990 mut place_builder : PlaceBuilder < ' tcx > ,
9091 pattern : & Pat < ' tcx > ,
9192 cx : & mut Builder < ' _ , ' tcx > ,
92- ) -> MatchPairTree < ' tcx > {
93+ match_pairs : & mut Vec < Self > , // Newly-created nodes are added to this vector
94+ ) {
9395 // Force the place type to the pattern's type.
9496 // FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
9597 if let Some ( resolved) = place_builder. resolve_upvar ( cx) {
@@ -142,7 +144,7 @@ impl<'tcx> MatchPairTree<'tcx> {
142144 variance,
143145 } ) ;
144146
145- subpairs . push ( MatchPairTree :: for_pattern ( place_builder, subpattern, cx) ) ;
147+ MatchPairTree :: for_pattern ( place_builder, subpattern, cx, & mut subpairs ) ;
146148 TestCase :: Irrefutable { ascription, binding : None }
147149 }
148150
@@ -156,13 +158,13 @@ impl<'tcx> MatchPairTree<'tcx> {
156158
157159 if let Some ( subpattern) = subpattern. as_ref ( ) {
158160 // this is the `x @ P` case; have to keep matching against `P` now
159- subpairs . push ( MatchPairTree :: for_pattern ( place_builder, subpattern, cx) ) ;
161+ MatchPairTree :: for_pattern ( place_builder, subpattern, cx, & mut subpairs ) ;
160162 }
161163 TestCase :: Irrefutable { ascription : None , binding }
162164 }
163165
164166 PatKind :: ExpandedConstant { subpattern : ref pattern, def_id : _, is_inline : false } => {
165- subpairs . push ( MatchPairTree :: for_pattern ( place_builder, pattern, cx) ) ;
167+ MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs ) ;
166168 default_irrefutable ( )
167169 }
168170 PatKind :: ExpandedConstant { subpattern : ref pattern, def_id, is_inline : true } => {
@@ -189,7 +191,7 @@ impl<'tcx> MatchPairTree<'tcx> {
189191 super :: Ascription { annotation, source, variance : ty:: Contravariant }
190192 } ) ;
191193
192- subpairs . push ( MatchPairTree :: for_pattern ( place_builder, pattern, cx) ) ;
194+ MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs ) ;
193195 TestCase :: Irrefutable { ascription, binding : None }
194196 }
195197
@@ -235,7 +237,7 @@ impl<'tcx> MatchPairTree<'tcx> {
235237 }
236238
237239 PatKind :: Deref { ref subpattern } => {
238- subpairs . push ( MatchPairTree :: for_pattern ( place_builder. deref ( ) , subpattern, cx) ) ;
240+ MatchPairTree :: for_pattern ( place_builder. deref ( ) , subpattern, cx, & mut subpairs ) ;
239241 default_irrefutable ( )
240242 }
241243
@@ -246,23 +248,24 @@ impl<'tcx> MatchPairTree<'tcx> {
246248 Ty :: new_ref ( cx. tcx , cx. tcx . lifetimes . re_erased , subpattern. ty , mutability) ,
247249 pattern. span ,
248250 ) ;
249- subpairs . push ( MatchPairTree :: for_pattern (
251+ MatchPairTree :: for_pattern (
250252 PlaceBuilder :: from ( temp) . deref ( ) ,
251253 subpattern,
252254 cx,
253- ) ) ;
255+ & mut subpairs,
256+ ) ;
254257 TestCase :: Deref { temp, mutability }
255258 }
256259
257260 PatKind :: Never => TestCase :: Never ,
258261 } ;
259262
260- MatchPairTree {
263+ match_pairs . push ( MatchPairTree {
261264 place,
262265 test_case,
263266 subpairs,
264267 pattern_ty : pattern. ty ,
265268 pattern_span : pattern. span ,
266- }
269+ } ) ;
267270 }
268271}
0 commit comments