@@ -95,27 +95,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
95
95
96
96
impl < ' pat , ' tcx > MatchPair < ' pat , ' tcx > {
97
97
pub ( in crate :: build) fn new (
98
- mut place : PlaceBuilder < ' tcx > ,
98
+ mut place_builder : PlaceBuilder < ' tcx > ,
99
99
pattern : & ' pat Pat < ' tcx > ,
100
100
cx : & mut Builder < ' _ , ' tcx > ,
101
101
) -> MatchPair < ' pat , ' tcx > {
102
102
// Force the place type to the pattern's type.
103
103
// FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
104
- if let Some ( resolved) = place . resolve_upvar ( cx) {
105
- place = resolved;
104
+ if let Some ( resolved) = place_builder . resolve_upvar ( cx) {
105
+ place_builder = resolved;
106
106
}
107
107
108
108
// Only add the OpaqueCast projection if the given place is an opaque type and the
109
109
// expected type from the pattern is not.
110
- let may_need_cast = match place . base ( ) {
110
+ let may_need_cast = match place_builder . base ( ) {
111
111
PlaceBase :: Local ( local) => {
112
- let ty = Place :: ty_from ( local, place. projection ( ) , & cx. local_decls , cx. tcx ) . ty ;
112
+ let ty =
113
+ Place :: ty_from ( local, place_builder. projection ( ) , & cx. local_decls , cx. tcx ) . ty ;
113
114
ty != pattern. ty && ty. has_opaque_types ( )
114
115
}
115
116
_ => true ,
116
117
} ;
117
118
if may_need_cast {
118
- place = place . project ( ProjectionElem :: OpaqueCast ( pattern. ty ) ) ;
119
+ place_builder = place_builder . project ( ProjectionElem :: OpaqueCast ( pattern. ty ) ) ;
119
120
}
120
121
121
122
let default_irrefutable = || TestCase :: Irrefutable { binding : None , ascription : None } ;
@@ -124,7 +125,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
124
125
PatKind :: Never | PatKind :: Wild | PatKind :: Error ( _) => default_irrefutable ( ) ,
125
126
PatKind :: Or { ref pats } => {
126
127
let pats: Box < [ _ ] > =
127
- pats. iter ( ) . map ( |pat| FlatPat :: new ( place . clone ( ) , pat, cx) ) . collect ( ) ;
128
+ pats. iter ( ) . map ( |pat| FlatPat :: new ( place_builder . clone ( ) , pat, cx) ) . collect ( ) ;
128
129
let simple = pats. iter ( ) . all ( |fpat| fpat. simple ) ;
129
130
TestCase :: Or { pats, simple }
130
131
}
@@ -145,13 +146,13 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
145
146
..
146
147
} => {
147
148
// Apply the type ascription to the value at `match_pair.place`
148
- let ascription = place . try_to_place ( cx) . map ( |source| super :: Ascription {
149
+ let ascription = place_builder . try_to_place ( cx) . map ( |source| super :: Ascription {
149
150
annotation : annotation. clone ( ) ,
150
151
source,
151
152
variance,
152
153
} ) ;
153
154
154
- subpairs. push ( MatchPair :: new ( place . clone ( ) , subpattern, cx) ) ;
155
+ subpairs. push ( MatchPair :: new ( place_builder . clone ( ) , subpattern, cx) ) ;
155
156
TestCase :: Irrefutable { ascription, binding : None }
156
157
}
157
158
@@ -164,7 +165,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
164
165
ref subpattern,
165
166
is_primary : _,
166
167
} => {
167
- let binding = place . try_to_place ( cx) . map ( |source| super :: Binding {
168
+ let binding = place_builder . try_to_place ( cx) . map ( |source| super :: Binding {
168
169
span : pattern. span ,
169
170
source,
170
171
var_id : var,
@@ -173,14 +174,14 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
173
174
174
175
if let Some ( subpattern) = subpattern. as_ref ( ) {
175
176
// this is the `x @ P` case; have to keep matching against `P` now
176
- subpairs. push ( MatchPair :: new ( place . clone ( ) , subpattern, cx) ) ;
177
+ subpairs. push ( MatchPair :: new ( place_builder . clone ( ) , subpattern, cx) ) ;
177
178
}
178
179
TestCase :: Irrefutable { ascription : None , binding }
179
180
}
180
181
181
182
PatKind :: InlineConstant { subpattern : ref pattern, def, .. } => {
182
183
// Apply a type ascription for the inline constant to the value at `match_pair.place`
183
- let ascription = place . try_to_place ( cx) . map ( |source| {
184
+ let ascription = place_builder . try_to_place ( cx) . map ( |source| {
184
185
let span = pattern. span ;
185
186
let parent_id = cx. tcx . typeck_root_def_id ( cx. def_id . to_def_id ( ) ) ;
186
187
let args = ty:: InlineConstArgs :: new (
@@ -206,16 +207,16 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
206
207
super :: Ascription { annotation, source, variance : ty:: Contravariant }
207
208
} ) ;
208
209
209
- subpairs. push ( MatchPair :: new ( place . clone ( ) , pattern, cx) ) ;
210
+ subpairs. push ( MatchPair :: new ( place_builder . clone ( ) , pattern, cx) ) ;
210
211
TestCase :: Irrefutable { ascription, binding : None }
211
212
}
212
213
213
214
PatKind :: Array { ref prefix, ref slice, ref suffix } => {
214
- cx. prefix_slice_suffix ( & mut subpairs, & place , prefix, slice, suffix) ;
215
+ cx. prefix_slice_suffix ( & mut subpairs, & place_builder , prefix, slice, suffix) ;
215
216
default_irrefutable ( )
216
217
}
217
218
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
218
- cx. prefix_slice_suffix ( & mut subpairs, & place , prefix, slice, suffix) ;
219
+ cx. prefix_slice_suffix ( & mut subpairs, & place_builder , prefix, slice, suffix) ;
219
220
220
221
if prefix. is_empty ( ) && slice. is_some ( ) && suffix. is_empty ( ) {
221
222
default_irrefutable ( )
@@ -228,7 +229,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
228
229
}
229
230
230
231
PatKind :: Variant { adt_def, variant_index, args, ref subpatterns } => {
231
- let downcast_place = place . clone ( ) . downcast ( adt_def, variant_index) ; // `(x as Variant)`
232
+ let downcast_place = place_builder . clone ( ) . downcast ( adt_def, variant_index) ; // `(x as Variant)`
232
233
subpairs = cx. field_match_pairs ( downcast_place, subpatterns) ;
233
234
234
235
let irrefutable = adt_def. variants ( ) . iter_enumerated ( ) . all ( |( i, v) | {
@@ -250,18 +251,18 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
250
251
}
251
252
252
253
PatKind :: Leaf { ref subpatterns } => {
253
- subpairs = cx. field_match_pairs ( place . clone ( ) , subpatterns) ;
254
+ subpairs = cx. field_match_pairs ( place_builder . clone ( ) , subpatterns) ;
254
255
default_irrefutable ( )
255
256
}
256
257
257
258
PatKind :: Deref { ref subpattern } => {
258
- let place_builder = place . clone ( ) . deref ( ) ;
259
+ let place_builder = place_builder . clone ( ) . deref ( ) ;
259
260
subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
260
261
default_irrefutable ( )
261
262
}
262
263
} ;
263
264
264
- MatchPair { place, test_case, subpairs, pattern }
265
+ MatchPair { place : place_builder , test_case, subpairs, pattern }
265
266
}
266
267
267
268
/// Whether this recursively contains no bindings or ascriptions.
0 commit comments