@@ -95,35 +95,37 @@ 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
122
+ let place = place_builder. try_to_place ( cx) ;
121
123
let default_irrefutable = || TestCase :: Irrefutable { binding : None , ascription : None } ;
122
124
let mut subpairs = Vec :: new ( ) ;
123
125
let test_case = match pattern. kind {
124
126
PatKind :: Never | PatKind :: Wild | PatKind :: Error ( _) => default_irrefutable ( ) ,
125
127
PatKind :: Or { ref pats } => TestCase :: Or {
126
- pats : pats. iter ( ) . map ( |pat| FlatPat :: new ( place . clone ( ) , pat, cx) ) . collect ( ) ,
128
+ pats : pats. iter ( ) . map ( |pat| FlatPat :: new ( place_builder . clone ( ) , pat, cx) ) . collect ( ) ,
127
129
} ,
128
130
129
131
PatKind :: Range ( ref range) => {
@@ -142,13 +144,13 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
142
144
..
143
145
} => {
144
146
// Apply the type ascription to the value at `match_pair.place`
145
- let ascription = place. try_to_place ( cx ) . map ( |source| super :: Ascription {
147
+ let ascription = place. map ( |source| super :: Ascription {
146
148
annotation : annotation. clone ( ) ,
147
149
source,
148
150
variance,
149
151
} ) ;
150
152
151
- subpairs. push ( MatchPair :: new ( place . clone ( ) , subpattern, cx) ) ;
153
+ subpairs. push ( MatchPair :: new ( place_builder , subpattern, cx) ) ;
152
154
TestCase :: Irrefutable { ascription, binding : None }
153
155
}
154
156
@@ -161,7 +163,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
161
163
ref subpattern,
162
164
is_primary : _,
163
165
} => {
164
- let binding = place. try_to_place ( cx ) . map ( |source| super :: Binding {
166
+ let binding = place. map ( |source| super :: Binding {
165
167
span : pattern. span ,
166
168
source,
167
169
var_id : var,
@@ -170,14 +172,14 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
170
172
171
173
if let Some ( subpattern) = subpattern. as_ref ( ) {
172
174
// this is the `x @ P` case; have to keep matching against `P` now
173
- subpairs. push ( MatchPair :: new ( place . clone ( ) , subpattern, cx) ) ;
175
+ subpairs. push ( MatchPair :: new ( place_builder , subpattern, cx) ) ;
174
176
}
175
177
TestCase :: Irrefutable { ascription : None , binding }
176
178
}
177
179
178
180
PatKind :: InlineConstant { subpattern : ref pattern, def, .. } => {
179
181
// Apply a type ascription for the inline constant to the value at `match_pair.place`
180
- let ascription = place. try_to_place ( cx ) . map ( |source| {
182
+ let ascription = place. map ( |source| {
181
183
let span = pattern. span ;
182
184
let parent_id = cx. tcx . typeck_root_def_id ( cx. def_id . to_def_id ( ) ) ;
183
185
let args = ty:: InlineConstArgs :: new (
@@ -203,16 +205,16 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
203
205
super :: Ascription { annotation, source, variance : ty:: Contravariant }
204
206
} ) ;
205
207
206
- subpairs. push ( MatchPair :: new ( place . clone ( ) , pattern, cx) ) ;
208
+ subpairs. push ( MatchPair :: new ( place_builder , pattern, cx) ) ;
207
209
TestCase :: Irrefutable { ascription, binding : None }
208
210
}
209
211
210
212
PatKind :: Array { ref prefix, ref slice, ref suffix } => {
211
- cx. prefix_slice_suffix ( & mut subpairs, & place , prefix, slice, suffix) ;
213
+ cx. prefix_slice_suffix ( & mut subpairs, & place_builder , prefix, slice, suffix) ;
212
214
default_irrefutable ( )
213
215
}
214
216
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
215
- cx. prefix_slice_suffix ( & mut subpairs, & place , prefix, slice, suffix) ;
217
+ cx. prefix_slice_suffix ( & mut subpairs, & place_builder , prefix, slice, suffix) ;
216
218
217
219
if prefix. is_empty ( ) && slice. is_some ( ) && suffix. is_empty ( ) {
218
220
default_irrefutable ( )
@@ -225,7 +227,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
225
227
}
226
228
227
229
PatKind :: Variant { adt_def, variant_index, args, ref subpatterns } => {
228
- let downcast_place = place . clone ( ) . downcast ( adt_def, variant_index) ; // `(x as Variant)`
230
+ let downcast_place = place_builder . downcast ( adt_def, variant_index) ; // `(x as Variant)`
229
231
subpairs = cx. field_match_pairs ( downcast_place, subpatterns) ;
230
232
231
233
let irrefutable = adt_def. variants ( ) . iter_enumerated ( ) . all ( |( i, v) | {
@@ -247,13 +249,12 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
247
249
}
248
250
249
251
PatKind :: Leaf { ref subpatterns } => {
250
- subpairs = cx. field_match_pairs ( place . clone ( ) , subpatterns) ;
252
+ subpairs = cx. field_match_pairs ( place_builder , subpatterns) ;
251
253
default_irrefutable ( )
252
254
}
253
255
254
256
PatKind :: Deref { ref subpattern } => {
255
- let place_builder = place. clone ( ) . deref ( ) ;
256
- subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
257
+ subpairs. push ( MatchPair :: new ( place_builder. deref ( ) , subpattern, cx) ) ;
257
258
default_irrefutable ( )
258
259
}
259
260
@@ -310,8 +311,8 @@ impl<'a, 'b, 'tcx> FakeBorrowCollector<'a, 'b, 'tcx> {
310
311
}
311
312
} else {
312
313
// Insert a Shallow borrow of any place that is switched on.
313
- if let Some ( resolved_place ) = match_pair. place . try_to_place ( self . cx ) {
314
- self . fake_borrows . insert ( resolved_place ) ;
314
+ if let Some ( place ) = match_pair. place {
315
+ self . fake_borrows . insert ( place ) ;
315
316
}
316
317
317
318
for subpair in & match_pair. subpairs {
0 commit comments