@@ -220,8 +220,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
220220 let cause_matched_place = FakeReadCause :: ForMatchedPlace ( None ) ;
221221 let source_info = self . source_info ( scrutinee_span) ;
222222
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 ) {
225224 self . cfg . push_fake_read ( block, source_info, cause_matched_place, scrutinee_place) ;
226225 }
227226
@@ -334,7 +333,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
334333 let arm_scope = ( arm. scope , arm_source_info) ;
335334 let match_scope = self . local_scope ( ) ;
336335 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
338337 // `PlaceBuilder` inside a closure. In this case, we don't want to include
339338 // a scrutinee place. `scrutinee_place_builder` will fail to be resolved
340339 // if the only match arm is a wildcard (`_`).
@@ -345,14 +344,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
345344 // match foo { _ => () };
346345 // };
347346 // ```
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) ) ;
356350 let scope = this. declare_bindings (
357351 None ,
358352 arm. span ,
@@ -591,7 +585,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
591585 while let Some ( next) = {
592586 for binding in & candidate_ref. bindings {
593587 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
595589 // `PlaceBuilder` inside a closure. In this case, we don't want to include
596590 // a scrutinee place. `scrutinee_place_builder` will fail for destructured
597591 // assignments. This is because a closure only captures the precise places
@@ -605,9 +599,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
605599 // let (v1, v2) = foo;
606600 // };
607601 // ```
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 ) {
611603 let Some ( box LocalInfo :: User ( ClearCrossCrate :: Set ( BindingForm :: Var (
612604 VarBindingForm { opt_match_place : Some ( ( ref mut match_place, _) ) , .. } ,
613605 ) ) ) ) = self . local_decls [ local] . local_info else {
@@ -1594,10 +1586,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15941586 }
15951587
15961588 // 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 )
15991591 {
1600- let resolved_place = match_place_resolved. into_place ( self ) ;
16011592 fb. insert ( resolved_place) ;
16021593 }
16031594
@@ -1788,12 +1779,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17881779 false ,
17891780 & mut [ & mut guard_candidate, & mut otherwise_candidate] ,
17901781 ) ;
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) ) ;
17971784 let otherwise_post_guard_block = otherwise_candidate. pre_binding_block . unwrap ( ) ;
17981785 self . break_for_else ( otherwise_post_guard_block, else_target, self . source_info ( expr_span) ) ;
17991786
0 commit comments