@@ -22,7 +22,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
22
22
) {
23
23
for fieldpat in subpatterns {
24
24
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 ) ;
26
26
}
27
27
}
28
28
@@ -53,11 +53,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
53
53
( ( prefix. len ( ) + suffix. len ( ) ) . try_into ( ) . unwrap ( ) , false )
54
54
} ;
55
55
56
- match_pairs . extend ( prefix. iter ( ) . enumerate ( ) . map ( | ( idx , subpattern ) | {
56
+ for ( idx , subpattern ) in prefix. iter ( ) . enumerate ( ) {
57
57
let elem =
58
58
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
+ }
61
62
62
63
if let Some ( subslice_pat) = opt_slice {
63
64
let suffix_len = suffix. len ( ) as u64 ;
@@ -66,19 +67,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
66
67
to : if exact_size { min_length - suffix_len } else { suffix_len } ,
67
68
from_end : !exact_size,
68
69
} ) ;
69
- match_pairs . push ( MatchPairTree :: for_pattern ( subslice, subslice_pat, self ) ) ;
70
+ MatchPairTree :: for_pattern ( subslice, subslice_pat, self , match_pairs ) ;
70
71
}
71
72
72
- match_pairs . extend ( suffix. iter ( ) . rev ( ) . enumerate ( ) . map ( | ( idx , subpattern ) | {
73
+ for ( idx , subpattern ) in suffix. iter ( ) . rev ( ) . enumerate ( ) {
73
74
let end_offset = ( idx + 1 ) as u64 ;
74
75
let elem = ProjectionElem :: ConstantIndex {
75
76
offset : if exact_size { min_length - end_offset } else { end_offset } ,
76
77
min_length,
77
78
from_end : !exact_size,
78
79
} ;
79
80
let place = place. clone_project ( elem) ;
80
- MatchPairTree :: for_pattern ( place, subpattern, self )
81
- } ) ) ;
81
+ MatchPairTree :: for_pattern ( place, subpattern, self , match_pairs ) ;
82
+ }
82
83
}
83
84
}
84
85
@@ -89,7 +90,8 @@ impl<'tcx> MatchPairTree<'tcx> {
89
90
mut place_builder : PlaceBuilder < ' tcx > ,
90
91
pattern : & Pat < ' tcx > ,
91
92
cx : & mut Builder < ' _ , ' tcx > ,
92
- ) -> MatchPairTree < ' tcx > {
93
+ match_pairs : & mut Vec < Self > , // Newly-created nodes are added to this vector
94
+ ) {
93
95
// Force the place type to the pattern's type.
94
96
// FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
95
97
if let Some ( resolved) = place_builder. resolve_upvar ( cx) {
@@ -142,7 +144,7 @@ impl<'tcx> MatchPairTree<'tcx> {
142
144
variance,
143
145
} ) ;
144
146
145
- subpairs . push ( MatchPairTree :: for_pattern ( place_builder, subpattern, cx) ) ;
147
+ MatchPairTree :: for_pattern ( place_builder, subpattern, cx, & mut subpairs ) ;
146
148
TestCase :: Irrefutable { ascription, binding : None }
147
149
}
148
150
@@ -156,13 +158,13 @@ impl<'tcx> MatchPairTree<'tcx> {
156
158
157
159
if let Some ( subpattern) = subpattern. as_ref ( ) {
158
160
// 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 ) ;
160
162
}
161
163
TestCase :: Irrefutable { ascription : None , binding }
162
164
}
163
165
164
166
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 ) ;
166
168
default_irrefutable ( )
167
169
}
168
170
PatKind :: ExpandedConstant { subpattern : ref pattern, def_id, is_inline : true } => {
@@ -189,7 +191,7 @@ impl<'tcx> MatchPairTree<'tcx> {
189
191
super :: Ascription { annotation, source, variance : ty:: Contravariant }
190
192
} ) ;
191
193
192
- subpairs . push ( MatchPairTree :: for_pattern ( place_builder, pattern, cx) ) ;
194
+ MatchPairTree :: for_pattern ( place_builder, pattern, cx, & mut subpairs ) ;
193
195
TestCase :: Irrefutable { ascription, binding : None }
194
196
}
195
197
@@ -235,7 +237,7 @@ impl<'tcx> MatchPairTree<'tcx> {
235
237
}
236
238
237
239
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 ) ;
239
241
default_irrefutable ( )
240
242
}
241
243
@@ -246,23 +248,24 @@ impl<'tcx> MatchPairTree<'tcx> {
246
248
Ty :: new_ref ( cx. tcx , cx. tcx . lifetimes . re_erased , subpattern. ty , mutability) ,
247
249
pattern. span ,
248
250
) ;
249
- subpairs . push ( MatchPairTree :: for_pattern (
251
+ MatchPairTree :: for_pattern (
250
252
PlaceBuilder :: from ( temp) . deref ( ) ,
251
253
subpattern,
252
254
cx,
253
- ) ) ;
255
+ & mut subpairs,
256
+ ) ;
254
257
TestCase :: Deref { temp, mutability }
255
258
}
256
259
257
260
PatKind :: Never => TestCase :: Never ,
258
261
} ;
259
262
260
- MatchPairTree {
263
+ match_pairs . push ( MatchPairTree {
261
264
place,
262
265
test_case,
263
266
subpairs,
264
267
pattern_ty : pattern. ty ,
265
268
pattern_span : pattern. span ,
266
- }
269
+ } ) ;
267
270
}
268
271
}
0 commit comments