@@ -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 {
@@ -146,13 +147,13 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
146
147
..
147
148
} => {
148
149
// Apply the type ascription to the value at `match_pair.place`
149
- let ascription = place_builder . try_to_place ( cx ) . map ( |source| super :: Ascription {
150
+ let ascription = place . map ( |source| super :: Ascription {
150
151
annotation : annotation. clone ( ) ,
151
152
source,
152
153
variance,
153
154
} ) ;
154
155
155
- subpairs. push ( MatchPair :: new ( place_builder. clone ( ) , subpattern, cx) ) ;
156
+ subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
156
157
TestCase :: Irrefutable { ascription, binding : None }
157
158
}
158
159
@@ -165,7 +166,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
165
166
ref subpattern,
166
167
is_primary : _,
167
168
} => {
168
- let binding = place_builder . try_to_place ( cx ) . map ( |source| super :: Binding {
169
+ let binding = place . map ( |source| super :: Binding {
169
170
span : pattern. span ,
170
171
source,
171
172
var_id : var,
@@ -174,14 +175,14 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
174
175
175
176
if let Some ( subpattern) = subpattern. as_ref ( ) {
176
177
// this is the `x @ P` case; have to keep matching against `P` now
177
- subpairs. push ( MatchPair :: new ( place_builder. clone ( ) , subpattern, cx) ) ;
178
+ subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
178
179
}
179
180
TestCase :: Irrefutable { ascription : None , binding }
180
181
}
181
182
182
183
PatKind :: InlineConstant { subpattern : ref pattern, def, .. } => {
183
184
// Apply a type ascription for the inline constant to the value at `match_pair.place`
184
- let ascription = place_builder . try_to_place ( cx ) . map ( |source| {
185
+ let ascription = place . map ( |source| {
185
186
let span = pattern. span ;
186
187
let parent_id = cx. tcx . typeck_root_def_id ( cx. def_id . to_def_id ( ) ) ;
187
188
let args = ty:: InlineConstArgs :: new (
@@ -207,7 +208,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
207
208
super :: Ascription { annotation, source, variance : ty:: Contravariant }
208
209
} ) ;
209
210
210
- subpairs. push ( MatchPair :: new ( place_builder. clone ( ) , pattern, cx) ) ;
211
+ subpairs. push ( MatchPair :: new ( place_builder, pattern, cx) ) ;
211
212
TestCase :: Irrefutable { ascription, binding : None }
212
213
}
213
214
@@ -229,7 +230,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
229
230
}
230
231
231
232
PatKind :: Variant { adt_def, variant_index, args, ref subpatterns } => {
232
- let downcast_place = place_builder. clone ( ) . downcast ( adt_def, variant_index) ; // `(x as Variant)`
233
+ let downcast_place = place_builder. downcast ( adt_def, variant_index) ; // `(x as Variant)`
233
234
subpairs = cx. field_match_pairs ( downcast_place, subpatterns) ;
234
235
235
236
let irrefutable = adt_def. variants ( ) . iter_enumerated ( ) . all ( |( i, v) | {
@@ -251,18 +252,17 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
251
252
}
252
253
253
254
PatKind :: Leaf { ref subpatterns } => {
254
- subpairs = cx. field_match_pairs ( place_builder. clone ( ) , subpatterns) ;
255
+ subpairs = cx. field_match_pairs ( place_builder, subpatterns) ;
255
256
default_irrefutable ( )
256
257
}
257
258
258
259
PatKind :: Deref { ref subpattern } => {
259
- let place_builder = place_builder. clone ( ) . deref ( ) ;
260
- subpairs. push ( MatchPair :: new ( place_builder, subpattern, cx) ) ;
260
+ subpairs. push ( MatchPair :: new ( place_builder. deref ( ) , subpattern, cx) ) ;
261
261
default_irrefutable ( )
262
262
}
263
263
} ;
264
264
265
- MatchPair { place : place_builder , test_case, subpairs, pattern }
265
+ MatchPair { place, test_case, subpairs, pattern }
266
266
}
267
267
268
268
/// Whether this recursively contains no bindings or ascriptions.
@@ -314,8 +314,8 @@ impl<'a, 'b, 'tcx> FakeBorrowCollector<'a, 'b, 'tcx> {
314
314
}
315
315
} else {
316
316
// Insert a Shallow borrow of any place that is switched on.
317
- if let Some ( resolved_place ) = match_pair. place . try_to_place ( self . cx ) {
318
- self . fake_borrows . insert ( resolved_place ) ;
317
+ if let Some ( place ) = match_pair. place {
318
+ self . fake_borrows . insert ( place ) ;
319
319
}
320
320
321
321
for subpair in & match_pair. subpairs {
0 commit comments