@@ -9,24 +9,21 @@ use crate::builder::expr::as_place::{PlaceBase, PlaceBuilder};
9
9
use crate :: builder:: matches:: { FlatPat , MatchPairTree , TestCase } ;
10
10
11
11
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
12
- /// Builds and returns [`MatchPairTree`] subtrees, one for each pattern in
12
+ /// Builds and pushes [`MatchPairTree`] subtrees, one for each pattern in
13
13
/// `subpatterns`, representing the fields of a [`PatKind::Variant`] or
14
14
/// [`PatKind::Leaf`].
15
15
///
16
16
/// Used internally by [`MatchPairTree::for_pattern`].
17
17
fn field_match_pairs (
18
18
& mut self ,
19
+ match_pairs : & mut Vec < MatchPairTree < ' tcx > > ,
19
20
place : PlaceBuilder < ' tcx > ,
20
21
subpatterns : & [ FieldPat < ' tcx > ] ,
21
- ) -> Vec < MatchPairTree < ' tcx > > {
22
- subpatterns
23
- . iter ( )
24
- . map ( |fieldpat| {
25
- let place =
26
- place. clone_project ( PlaceElem :: Field ( fieldpat. field , fieldpat. pattern . ty ) ) ;
27
- MatchPairTree :: for_pattern ( place, & fieldpat. pattern , self )
28
- } )
29
- . collect ( )
22
+ ) {
23
+ for fieldpat in subpatterns {
24
+ let place = place. clone_project ( PlaceElem :: Field ( fieldpat. field , fieldpat. pattern . ty ) ) ;
25
+ match_pairs. push ( MatchPairTree :: for_pattern ( place, & fieldpat. pattern , self ) ) ;
26
+ }
30
27
}
31
28
32
29
/// Builds [`MatchPairTree`] subtrees for the prefix/middle/suffix parts of an
@@ -215,7 +212,7 @@ impl<'tcx> MatchPairTree<'tcx> {
215
212
216
213
PatKind :: Variant { adt_def, variant_index, args, ref subpatterns } => {
217
214
let downcast_place = place_builder. downcast ( adt_def, variant_index) ; // `(x as Variant)`
218
- subpairs = cx. field_match_pairs ( downcast_place, subpatterns) ;
215
+ cx. field_match_pairs ( & mut subpairs , downcast_place, subpatterns) ;
219
216
220
217
let irrefutable = adt_def. variants ( ) . iter_enumerated ( ) . all ( |( i, v) | {
221
218
i == variant_index
@@ -233,7 +230,7 @@ impl<'tcx> MatchPairTree<'tcx> {
233
230
}
234
231
235
232
PatKind :: Leaf { ref subpatterns } => {
236
- subpairs = cx. field_match_pairs ( place_builder, subpatterns) ;
233
+ cx. field_match_pairs ( & mut subpairs , place_builder, subpatterns) ;
237
234
default_irrefutable ( )
238
235
}
239
236
0 commit comments