@@ -3,37 +3,37 @@ use rustc_middle::thir::{self, *};
33use rustc_middle:: ty:: { self , Ty , TypeVisitableExt } ;
44
55use crate :: build:: expr:: as_place:: { PlaceBase , PlaceBuilder } ;
6- use crate :: build:: matches:: { FlatPat , MatchPair , TestCase } ;
6+ use crate :: build:: matches:: { FlatPat , MatchPairTree , TestCase } ;
77use crate :: build:: Builder ;
88
99impl < ' 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
1111 /// `subpatterns`, representing the fields of a [`PatKind::Variant`] or
1212 /// [`PatKind::Leaf`].
1313 ///
14- /// Used internally by [`MatchPair::new `].
14+ /// Used internally by [`MatchPairTree::for_pattern `].
1515 fn field_match_pairs < ' pat > (
1616 & mut self ,
1717 place : PlaceBuilder < ' tcx > ,
1818 subpatterns : & ' pat [ FieldPat < ' tcx > ] ,
19- ) -> Vec < MatchPair < ' pat , ' tcx > > {
19+ ) -> Vec < MatchPairTree < ' pat , ' tcx > > {
2020 subpatterns
2121 . iter ( )
2222 . map ( |fieldpat| {
2323 let place =
2424 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 )
2626 } )
2727 . collect ( )
2828 }
2929
30- /// Builds [`MatchPair `] trees for the prefix/middle/suffix parts of an
30+ /// Builds [`MatchPairTree `] subtrees for the prefix/middle/suffix parts of an
3131 /// array pattern or slice pattern, and adds those trees to `match_pairs`.
3232 ///
33- /// Used internally by [`MatchPair::new `].
33+ /// Used internally by [`MatchPairTree::for_pattern `].
3434 fn prefix_slice_suffix < ' pat > (
3535 & mut self ,
36- match_pairs : & mut Vec < MatchPair < ' pat , ' tcx > > ,
36+ match_pairs : & mut Vec < MatchPairTree < ' pat , ' tcx > > ,
3737 place : & PlaceBuilder < ' tcx > ,
3838 prefix : & ' pat [ Box < Pat < ' tcx > > ] ,
3939 opt_slice : & ' pat Option < Box < Pat < ' tcx > > > ,
@@ -52,7 +52,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5252 match_pairs. extend ( prefix. iter ( ) . enumerate ( ) . map ( |( idx, subpattern) | {
5353 let elem =
5454 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 )
5656 } ) ) ;
5757
5858 if let Some ( subslice_pat) = opt_slice {
@@ -62,7 +62,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6262 to : if exact_size { min_length - suffix_len } else { suffix_len } ,
6363 from_end : !exact_size,
6464 } ) ;
65- match_pairs. push ( MatchPair :: new ( subslice, subslice_pat, self ) ) ;
65+ match_pairs. push ( MatchPairTree :: for_pattern ( subslice, subslice_pat, self ) ) ;
6666 }
6767
6868 match_pairs. extend ( suffix. iter ( ) . rev ( ) . enumerate ( ) . map ( |( idx, subpattern) | {
@@ -73,19 +73,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7373 from_end : !exact_size,
7474 } ;
7575 let place = place. clone_project ( elem) ;
76- MatchPair :: new ( place, subpattern, self )
76+ MatchPairTree :: for_pattern ( place, subpattern, self )
7777 } ) ) ;
7878 }
7979}
8080
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
8383 /// subpatterns.
84- pub ( in crate :: build) fn new (
84+ pub ( in crate :: build) fn for_pattern (
8585 mut place_builder : PlaceBuilder < ' tcx > ,
8686 pattern : & ' pat Pat < ' tcx > ,
8787 cx : & mut Builder < ' _ , ' tcx > ,
88- ) -> MatchPair < ' pat , ' tcx > {
88+ ) -> MatchPairTree < ' pat , ' tcx > {
8989 // Force the place type to the pattern's type.
9090 // FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
9191 if let Some ( resolved) = place_builder. resolve_upvar ( cx) {
@@ -138,7 +138,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
138138 variance,
139139 } ) ;
140140
141- subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
141+ subpairs. push ( MatchPairTree :: for_pattern ( place_builder, subpattern, cx) ) ;
142142 TestCase :: Irrefutable { ascription, binding : None }
143143 }
144144
@@ -152,7 +152,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
152152
153153 if let Some ( subpattern) = subpattern. as_ref ( ) {
154154 // 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) ) ;
156156 }
157157 TestCase :: Irrefutable { ascription : None , binding }
158158 }
@@ -182,7 +182,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
182182 super :: Ascription { annotation, source, variance : ty:: Contravariant }
183183 } ) ;
184184
185- subpairs. push ( MatchPair :: new ( place_builder, pattern, cx) ) ;
185+ subpairs. push ( MatchPairTree :: for_pattern ( place_builder, pattern, cx) ) ;
186186 TestCase :: Irrefutable { ascription, binding : None }
187187 }
188188
@@ -231,7 +231,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
231231 }
232232
233233 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) ) ;
235235 default_irrefutable ( )
236236 }
237237
@@ -242,13 +242,17 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
242242 Ty :: new_ref ( cx. tcx , cx. tcx . lifetimes . re_erased , subpattern. ty , mutability) ,
243243 pattern. span ,
244244 ) ;
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+ ) ) ;
246250 TestCase :: Deref { temp, mutability }
247251 }
248252
249253 PatKind :: Never => TestCase :: Never ,
250254 } ;
251255
252- MatchPair { place, test_case, subpairs, pattern }
256+ MatchPairTree { place, test_case, subpairs, pattern }
253257 }
254258}
0 commit comments