@@ -220,8 +220,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
220
220
let cause_matched_place = FakeReadCause :: ForMatchedPlace ( None ) ;
221
221
let source_info = self . source_info ( scrutinee_span) ;
222
222
223
- if let Ok ( scrutinee_builder) = scrutinee_place_builder. clone ( ) . try_upvars_resolved ( self ) {
224
- let scrutinee_place = scrutinee_builder. into_place ( self ) ;
223
+ if let Some ( scrutinee_place) = scrutinee_place_builder. try_to_place ( self ) {
225
224
self . cfg . push_fake_read ( block, source_info, cause_matched_place, scrutinee_place) ;
226
225
}
227
226
@@ -334,7 +333,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
334
333
let arm_scope = ( arm. scope , arm_source_info) ;
335
334
let match_scope = self . local_scope ( ) ;
336
335
self . in_scope ( arm_scope, arm. lint_level , |this| {
337
- // `try_upvars_resolved ` may fail if it is unable to resolve the given
336
+ // `try_to_place ` may fail if it is unable to resolve the given
338
337
// `PlaceBuilder` inside a closure. In this case, we don't want to include
339
338
// a scrutinee place. `scrutinee_place_builder` will fail to be resolved
340
339
// if the only match arm is a wildcard (`_`).
@@ -345,14 +344,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
345
344
// match foo { _ => () };
346
345
// };
347
346
// ```
348
- let mut opt_scrutinee_place: Option < ( Option < & Place < ' tcx > > , Span ) > = None ;
349
- let scrutinee_place: Place < ' tcx > ;
350
- if let Ok ( scrutinee_builder) =
351
- scrutinee_place_builder. clone ( ) . try_upvars_resolved ( this)
352
- {
353
- scrutinee_place = scrutinee_builder. into_place ( this) ;
354
- opt_scrutinee_place = Some ( ( Some ( & scrutinee_place) , scrutinee_span) ) ;
355
- }
347
+ let scrutinee_place = scrutinee_place_builder. try_to_place ( this) ;
348
+ let opt_scrutinee_place =
349
+ scrutinee_place. as_ref ( ) . map ( |place| ( Some ( place) , scrutinee_span) ) ;
356
350
let scope = this. declare_bindings (
357
351
None ,
358
352
arm. span ,
@@ -591,7 +585,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
591
585
while let Some ( next) = {
592
586
for binding in & candidate_ref. bindings {
593
587
let local = self . var_local_id ( binding. var_id , OutsideGuard ) ;
594
- // `try_upvars_resolved ` may fail if it is unable to resolve the given
588
+ // `try_to_place ` may fail if it is unable to resolve the given
595
589
// `PlaceBuilder` inside a closure. In this case, we don't want to include
596
590
// a scrutinee place. `scrutinee_place_builder` will fail for destructured
597
591
// assignments. This is because a closure only captures the precise places
@@ -605,9 +599,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
605
599
// let (v1, v2) = foo;
606
600
// };
607
601
// ```
608
- if let Ok ( match_pair_resolved) = initializer. clone ( ) . try_upvars_resolved ( self ) {
609
- let place = match_pair_resolved. into_place ( self ) ;
610
-
602
+ if let Some ( place) = initializer. try_to_place ( self ) {
611
603
let Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: Var (
612
604
VarBindingForm { opt_match_place : Some ( ( ref mut match_place, _) ) , .. } ,
613
605
) ) ) ) = self . local_decls [ local] . local_info else {
@@ -1594,10 +1586,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1594
1586
}
1595
1587
1596
1588
// Insert a Shallow borrow of any places that is switched on.
1597
- if let Some ( fb) = fake_borrows && let Ok ( match_place_resolved ) =
1598
- match_place . clone ( ) . try_upvars_resolved ( self )
1589
+ if let Some ( fb) = fake_borrows
1590
+ && let Some ( resolved_place ) = match_place . try_to_place ( self )
1599
1591
{
1600
- let resolved_place = match_place_resolved. into_place ( self ) ;
1601
1592
fb. insert ( resolved_place) ;
1602
1593
}
1603
1594
@@ -1788,12 +1779,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1788
1779
false ,
1789
1780
& mut [ & mut guard_candidate, & mut otherwise_candidate] ,
1790
1781
) ;
1791
- let mut opt_expr_place: Option < ( Option < & Place < ' tcx > > , Span ) > = None ;
1792
- let expr_place: Place < ' tcx > ;
1793
- if let Ok ( expr_builder) = expr_place_builder. try_upvars_resolved ( self ) {
1794
- expr_place = expr_builder. into_place ( self ) ;
1795
- opt_expr_place = Some ( ( Some ( & expr_place) , expr_span) ) ;
1796
- }
1782
+ let expr_place = expr_place_builder. try_to_place ( self ) ;
1783
+ let opt_expr_place = expr_place. as_ref ( ) . map ( |place| ( Some ( place) , expr_span) ) ;
1797
1784
let otherwise_post_guard_block = otherwise_candidate. pre_binding_block . unwrap ( ) ;
1798
1785
self . break_for_else ( otherwise_post_guard_block, else_target, self . source_info ( expr_span) ) ;
1799
1786
0 commit comments