@@ -3,37 +3,37 @@ use rustc_middle::thir::{self, *};
3
3
use rustc_middle:: ty:: { self , Ty , TypeVisitableExt } ;
4
4
5
5
use crate :: build:: expr:: as_place:: { PlaceBase , PlaceBuilder } ;
6
- use crate :: build:: matches:: { FlatPat , MatchPair , TestCase } ;
6
+ use crate :: build:: matches:: { FlatPat , MatchPairTree , TestCase } ;
7
7
use crate :: build:: Builder ;
8
8
9
9
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
10
- /// Builds and returns [`MatchPair `] trees , one for each pattern in
10
+ /// Builds and returns [`MatchPairTree `] subtrees , one for each pattern in
11
11
/// `subpatterns`, representing the fields of a [`PatKind::Variant`] or
12
12
/// [`PatKind::Leaf`].
13
13
///
14
- /// Used internally by [`MatchPair::new `].
14
+ /// Used internally by [`MatchPairTree::for_pattern `].
15
15
fn field_match_pairs < ' pat > (
16
16
& mut self ,
17
17
place : PlaceBuilder < ' tcx > ,
18
18
subpatterns : & ' pat [ FieldPat < ' tcx > ] ,
19
- ) -> Vec < MatchPair < ' pat , ' tcx > > {
19
+ ) -> Vec < MatchPairTree < ' pat , ' tcx > > {
20
20
subpatterns
21
21
. iter ( )
22
22
. map ( |fieldpat| {
23
23
let place =
24
24
place. clone_project ( PlaceElem :: Field ( fieldpat. field , fieldpat. pattern . ty ) ) ;
25
- MatchPair :: new ( place, & fieldpat. pattern , self )
25
+ MatchPairTree :: for_pattern ( place, & fieldpat. pattern , self )
26
26
} )
27
27
. collect ( )
28
28
}
29
29
30
- /// Builds [`MatchPair `] trees for the prefix/middle/suffix parts of an
30
+ /// Builds [`MatchPairTree `] subtrees for the prefix/middle/suffix parts of an
31
31
/// array pattern or slice pattern, and adds those trees to `match_pairs`.
32
32
///
33
- /// Used internally by [`MatchPair::new `].
33
+ /// Used internally by [`MatchPairTree::for_pattern `].
34
34
fn prefix_slice_suffix < ' pat > (
35
35
& mut self ,
36
- match_pairs : & mut Vec < MatchPair < ' pat , ' tcx > > ,
36
+ match_pairs : & mut Vec < MatchPairTree < ' pat , ' tcx > > ,
37
37
place : & PlaceBuilder < ' tcx > ,
38
38
prefix : & ' pat [ Box < Pat < ' tcx > > ] ,
39
39
opt_slice : & ' pat Option < Box < Pat < ' tcx > > > ,
@@ -52,7 +52,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
52
52
match_pairs. extend ( prefix. iter ( ) . enumerate ( ) . map ( |( idx, subpattern) | {
53
53
let elem =
54
54
ProjectionElem :: ConstantIndex { offset : idx as u64 , min_length, from_end : false } ;
55
- MatchPair :: new ( place. clone_project ( elem) , subpattern, self )
55
+ MatchPairTree :: for_pattern ( place. clone_project ( elem) , subpattern, self )
56
56
} ) ) ;
57
57
58
58
if let Some ( subslice_pat) = opt_slice {
@@ -62,7 +62,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
62
62
to : if exact_size { min_length - suffix_len } else { suffix_len } ,
63
63
from_end : !exact_size,
64
64
} ) ;
65
- match_pairs. push ( MatchPair :: new ( subslice, subslice_pat, self ) ) ;
65
+ match_pairs. push ( MatchPairTree :: for_pattern ( subslice, subslice_pat, self ) ) ;
66
66
}
67
67
68
68
match_pairs. extend ( suffix. iter ( ) . rev ( ) . enumerate ( ) . map ( |( idx, subpattern) | {
@@ -73,19 +73,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
73
73
from_end : !exact_size,
74
74
} ;
75
75
let place = place. clone_project ( elem) ;
76
- MatchPair :: new ( place, subpattern, self )
76
+ MatchPairTree :: for_pattern ( place, subpattern, self )
77
77
} ) ) ;
78
78
}
79
79
}
80
80
81
- impl < ' pat , ' tcx > MatchPair < ' pat , ' tcx > {
82
- /// Recursively builds a `MatchPair` tree for the given pattern and its
81
+ impl < ' pat , ' tcx > MatchPairTree < ' pat , ' tcx > {
82
+ /// Recursively builds a match pair tree for the given pattern and its
83
83
/// subpatterns.
84
- pub ( in crate :: build) fn new (
84
+ pub ( in crate :: build) fn for_pattern (
85
85
mut place_builder : PlaceBuilder < ' tcx > ,
86
86
pattern : & ' pat Pat < ' tcx > ,
87
87
cx : & mut Builder < ' _ , ' tcx > ,
88
- ) -> MatchPair < ' pat , ' tcx > {
88
+ ) -> MatchPairTree < ' pat , ' tcx > {
89
89
// Force the place type to the pattern's type.
90
90
// FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
91
91
if let Some ( resolved) = place_builder. resolve_upvar ( cx) {
@@ -138,7 +138,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
138
138
variance,
139
139
} ) ;
140
140
141
- subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
141
+ subpairs. push ( MatchPairTree :: for_pattern ( place_builder, subpattern, cx) ) ;
142
142
TestCase :: Irrefutable { ascription, binding : None }
143
143
}
144
144
@@ -152,7 +152,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
152
152
153
153
if let Some ( subpattern) = subpattern. as_ref ( ) {
154
154
// this is the `x @ P` case; have to keep matching against `P` now
155
- subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
155
+ subpairs. push ( MatchPairTree :: for_pattern ( place_builder, subpattern, cx) ) ;
156
156
}
157
157
TestCase :: Irrefutable { ascription : None , binding }
158
158
}
@@ -182,7 +182,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
182
182
super :: Ascription { annotation, source, variance : ty:: Contravariant }
183
183
} ) ;
184
184
185
- subpairs. push ( MatchPair :: new ( place_builder, pattern, cx) ) ;
185
+ subpairs. push ( MatchPairTree :: for_pattern ( place_builder, pattern, cx) ) ;
186
186
TestCase :: Irrefutable { ascription, binding : None }
187
187
}
188
188
@@ -231,7 +231,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
231
231
}
232
232
233
233
PatKind :: Deref { ref subpattern } => {
234
- subpairs. push ( MatchPair :: new ( place_builder. deref ( ) , subpattern, cx) ) ;
234
+ subpairs. push ( MatchPairTree :: for_pattern ( place_builder. deref ( ) , subpattern, cx) ) ;
235
235
default_irrefutable ( )
236
236
}
237
237
@@ -242,13 +242,17 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
242
242
Ty :: new_ref ( cx. tcx , cx. tcx . lifetimes . re_erased , subpattern. ty , mutability) ,
243
243
pattern. span ,
244
244
) ;
245
- subpairs. push ( MatchPair :: new ( PlaceBuilder :: from ( temp) . deref ( ) , subpattern, cx) ) ;
245
+ subpairs. push ( MatchPairTree :: for_pattern (
246
+ PlaceBuilder :: from ( temp) . deref ( ) ,
247
+ subpattern,
248
+ cx,
249
+ ) ) ;
246
250
TestCase :: Deref { temp, mutability }
247
251
}
248
252
249
253
PatKind :: Never => TestCase :: Never ,
250
254
} ;
251
255
252
- MatchPair { place, test_case, subpairs, pattern }
256
+ MatchPairTree { place, test_case, subpairs, pattern }
253
257
}
254
258
}
0 commit comments