@@ -119,6 +119,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
119
119
place_builder = place_builder. project ( ProjectionElem :: OpaqueCast ( pattern. ty ) ) ;
120
120
}
121
121
122
+ let place = place_builder. try_to_place ( cx) ;
122
123
let default_irrefutable = || TestCase :: Irrefutable { binding : None , ascription : None } ;
123
124
let mut subpairs = Vec :: new ( ) ;
124
125
let test_case = match pattern. kind {
@@ -143,13 +144,13 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
143
144
..
144
145
} => {
145
146
// Apply the type ascription to the value at `match_pair.place`
146
- let ascription = place_builder . try_to_place ( cx ) . map ( |source| super :: Ascription {
147
+ let ascription = place . map ( |source| super :: Ascription {
147
148
annotation : annotation. clone ( ) ,
148
149
source,
149
150
variance,
150
151
} ) ;
151
152
152
- subpairs. push ( MatchPair :: new ( place_builder. clone ( ) , subpattern, cx) ) ;
153
+ subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
153
154
TestCase :: Irrefutable { ascription, binding : None }
154
155
}
155
156
@@ -162,7 +163,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
162
163
ref subpattern,
163
164
is_primary : _,
164
165
} => {
165
- let binding = place_builder . try_to_place ( cx ) . map ( |source| super :: Binding {
166
+ let binding = place . map ( |source| super :: Binding {
166
167
span : pattern. span ,
167
168
source,
168
169
var_id : var,
@@ -171,14 +172,14 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
171
172
172
173
if let Some ( subpattern) = subpattern. as_ref ( ) {
173
174
// this is the `x @ P` case; have to keep matching against `P` now
174
- subpairs. push ( MatchPair :: new ( place_builder. clone ( ) , subpattern, cx) ) ;
175
+ subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
175
176
}
176
177
TestCase :: Irrefutable { ascription : None , binding }
177
178
}
178
179
179
180
PatKind :: InlineConstant { subpattern : ref pattern, def, .. } => {
180
181
// Apply a type ascription for the inline constant to the value at `match_pair.place`
181
- let ascription = place_builder . try_to_place ( cx ) . map ( |source| {
182
+ let ascription = place . map ( |source| {
182
183
let span = pattern. span ;
183
184
let parent_id = cx. tcx . typeck_root_def_id ( cx. def_id . to_def_id ( ) ) ;
184
185
let args = ty:: InlineConstArgs :: new (
@@ -204,7 +205,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
204
205
super :: Ascription { annotation, source, variance : ty:: Contravariant }
205
206
} ) ;
206
207
207
- subpairs. push ( MatchPair :: new ( place_builder. clone ( ) , pattern, cx) ) ;
208
+ subpairs. push ( MatchPair :: new ( place_builder, pattern, cx) ) ;
208
209
TestCase :: Irrefutable { ascription, binding : None }
209
210
}
210
211
@@ -226,7 +227,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
226
227
}
227
228
228
229
PatKind :: Variant { adt_def, variant_index, args, ref subpatterns } => {
229
- let downcast_place = place_builder. clone ( ) . downcast ( adt_def, variant_index) ; // `(x as Variant)`
230
+ let downcast_place = place_builder. downcast ( adt_def, variant_index) ; // `(x as Variant)`
230
231
subpairs = cx. field_match_pairs ( downcast_place, subpatterns) ;
231
232
232
233
let irrefutable = adt_def. variants ( ) . iter_enumerated ( ) . all ( |( i, v) | {
@@ -248,13 +249,12 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
248
249
}
249
250
250
251
PatKind :: Leaf { ref subpatterns } => {
251
- subpairs = cx. field_match_pairs ( place_builder. clone ( ) , subpatterns) ;
252
+ subpairs = cx. field_match_pairs ( place_builder, subpatterns) ;
252
253
default_irrefutable ( )
253
254
}
254
255
255
256
PatKind :: Deref { ref subpattern } => {
256
- let place_builder = place_builder. clone ( ) . deref ( ) ;
257
- subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
257
+ subpairs. push ( MatchPair :: new ( place_builder. deref ( ) , subpattern, cx) ) ;
258
258
default_irrefutable ( )
259
259
}
260
260
@@ -265,7 +265,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
265
265
}
266
266
} ;
267
267
268
- MatchPair { place : place_builder , test_case, subpairs, pattern }
268
+ MatchPair { place, test_case, subpairs, pattern }
269
269
}
270
270
}
271
271
@@ -311,8 +311,8 @@ impl<'a, 'b, 'tcx> FakeBorrowCollector<'a, 'b, 'tcx> {
311
311
}
312
312
} else {
313
313
// Insert a Shallow borrow of any place that is switched on.
314
- if let Some ( resolved_place ) = match_pair. place . try_to_place ( self . cx ) {
315
- self . fake_borrows . insert ( resolved_place ) ;
314
+ if let Some ( place ) = match_pair. place {
315
+ self . fake_borrows . insert ( place ) ;
316
316
}
317
317
318
318
for subpair in & match_pair. subpairs {
0 commit comments