@@ -147,6 +147,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
147
147
Some ( args. variable_source_info . scope ) ,
148
148
args. variable_source_info . span ,
149
149
args. declare_let_bindings ,
150
+ false ,
150
151
) ,
151
152
_ => {
152
153
let mut block = block;
@@ -1981,48 +1982,50 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1981
1982
1982
1983
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
1983
1984
/// If the bindings have already been declared, set `declare_bindings` to
1984
- /// `false` to avoid duplicated bindings declaration. Used for if-let guards.
1985
+ /// `false` to avoid duplicated bindings declaration; used for if-let guards.
1985
1986
pub ( crate ) fn lower_let_expr (
1986
1987
& mut self ,
1987
1988
mut block : BasicBlock ,
1988
1989
expr_id : ExprId ,
1989
1990
pat : & Pat < ' tcx > ,
1990
1991
source_scope : Option < SourceScope > ,
1991
- span : Span ,
1992
+ scope_span : Span ,
1992
1993
declare_bindings : bool ,
1994
+ storages_alive : bool ,
1993
1995
) -> BlockAnd < ( ) > {
1994
1996
let expr_span = self . thir [ expr_id] . span ;
1995
- let expr_place_builder = unpack ! ( block = self . lower_scrutinee( block, expr_id, expr_span) ) ;
1996
- let mut guard_candidate = Candidate :: new ( expr_place_builder . clone ( ) , pat, false , self ) ;
1997
+ let scrutinee = unpack ! ( block = self . lower_scrutinee( block, expr_id, expr_span) ) ;
1998
+ let mut candidate = Candidate :: new ( scrutinee . clone ( ) , pat, false , self ) ;
1997
1999
let otherwise_block = self . lower_match_tree (
1998
2000
block,
2001
+ expr_span,
2002
+ & scrutinee,
1999
2003
pat. span ,
2000
- & expr_place_builder,
2001
- pat. span ,
2002
- & mut [ & mut guard_candidate] ,
2004
+ & mut [ & mut candidate] ,
2003
2005
true ,
2004
2006
) ;
2005
- let expr_place = expr_place_builder. try_to_place ( self ) ;
2006
- let opt_expr_place = expr_place. as_ref ( ) . map ( |place| ( Some ( place) , expr_span) ) ;
2007
+
2007
2008
self . break_for_else ( otherwise_block, self . source_info ( expr_span) ) ;
2008
2009
2009
2010
if declare_bindings {
2010
- self . declare_bindings ( source_scope, pat. span . to ( span) , pat, None , opt_expr_place) ;
2011
+ let expr_place = scrutinee. try_to_place ( self ) ;
2012
+ let opt_expr_place = expr_place. as_ref ( ) . map ( |place| ( Some ( place) , expr_span) ) ;
2013
+ self . declare_bindings ( source_scope, pat. span . to ( scope_span) , pat, None , opt_expr_place) ;
2011
2014
}
2012
2015
2013
- let post_guard_block = self . bind_pattern (
2016
+ let success = self . bind_pattern (
2014
2017
self . source_info ( pat. span ) ,
2015
- guard_candidate ,
2018
+ candidate ,
2016
2019
& [ ] ,
2017
2020
expr_span,
2018
2021
None ,
2019
- false ,
2022
+ storages_alive ,
2020
2023
) ;
2021
2024
2022
2025
// If branch coverage is enabled, record this branch.
2023
- self . visit_coverage_conditional_let ( pat, post_guard_block , otherwise_block) ;
2026
+ self . visit_coverage_conditional_let ( pat, success , otherwise_block) ;
2024
2027
2025
- post_guard_block . unit ( )
2028
+ success . unit ( )
2026
2029
}
2027
2030
2028
2031
/// Initializes each of the bindings from the candidate by
@@ -2469,44 +2472,4 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2469
2472
debug ! ( ?locals) ;
2470
2473
self . var_indices . insert ( var_id, locals) ;
2471
2474
}
2472
-
2473
- pub ( crate ) fn ast_let_else (
2474
- & mut self ,
2475
- mut block : BasicBlock ,
2476
- init_id : ExprId ,
2477
- initializer_span : Span ,
2478
- else_block : BlockId ,
2479
- let_else_scope : & region:: Scope ,
2480
- pattern : & Pat < ' tcx > ,
2481
- ) -> BlockAnd < BasicBlock > {
2482
- let else_block_span = self . thir [ else_block] . span ;
2483
- let ( matching, failure) = self . in_if_then_scope ( * let_else_scope, else_block_span, |this| {
2484
- let scrutinee = unpack ! ( block = this. lower_scrutinee( block, init_id, initializer_span) ) ;
2485
- let mut candidate = Candidate :: new ( scrutinee. clone ( ) , pattern, false , this) ;
2486
- let failure_block = this. lower_match_tree (
2487
- block,
2488
- initializer_span,
2489
- & scrutinee,
2490
- pattern. span ,
2491
- & mut [ & mut candidate] ,
2492
- true ,
2493
- ) ;
2494
- // This block is for the matching case
2495
- let matching = this. bind_pattern (
2496
- this. source_info ( pattern. span ) ,
2497
- candidate,
2498
- & [ ] ,
2499
- initializer_span,
2500
- None ,
2501
- true ,
2502
- ) ;
2503
-
2504
- // If branch coverage is enabled, record this branch.
2505
- this. visit_coverage_conditional_let ( pattern, matching, failure_block) ;
2506
-
2507
- this. break_for_else ( failure_block, this. source_info ( initializer_span) ) ;
2508
- matching. unit ( )
2509
- } ) ;
2510
- matching. and ( failure)
2511
- }
2512
2475
}
0 commit comments