@@ -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;
@@ -1995,48 +1996,50 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1995
1996
1996
1997
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
1997
1998
/// If the bindings have already been declared, set `declare_bindings` to
1998
- /// `false` to avoid duplicated bindings declaration. Used for if-let guards.
1999
+ /// `false` to avoid duplicated bindings declaration; used for if-let guards.
1999
2000
pub ( crate ) fn lower_let_expr (
2000
2001
& mut self ,
2001
2002
mut block : BasicBlock ,
2002
2003
expr_id : ExprId ,
2003
2004
pat : & Pat < ' tcx > ,
2004
2005
source_scope : Option < SourceScope > ,
2005
- span : Span ,
2006
+ scope_span : Span ,
2006
2007
declare_bindings : bool ,
2008
+ storages_alive : bool ,
2007
2009
) -> BlockAnd < ( ) > {
2008
2010
let expr_span = self . thir [ expr_id] . span ;
2009
- let expr_place_builder = unpack ! ( block = self . lower_scrutinee( block, expr_id, expr_span) ) ;
2010
- let mut guard_candidate = Candidate :: new ( expr_place_builder . clone ( ) , pat, false , self ) ;
2011
+ let scrutinee = unpack ! ( block = self . lower_scrutinee( block, expr_id, expr_span) ) ;
2012
+ let mut candidate = Candidate :: new ( scrutinee . clone ( ) , pat, false , self ) ;
2011
2013
let otherwise_block = self . lower_match_tree (
2012
2014
block,
2015
+ expr_span,
2016
+ & scrutinee,
2013
2017
pat. span ,
2014
- & expr_place_builder,
2015
- pat. span ,
2016
- & mut [ & mut guard_candidate] ,
2018
+ & mut [ & mut candidate] ,
2017
2019
true ,
2018
2020
) ;
2019
- let expr_place = expr_place_builder. try_to_place ( self ) ;
2020
- let opt_expr_place = expr_place. as_ref ( ) . map ( |place| ( Some ( place) , expr_span) ) ;
2021
+
2021
2022
self . break_for_else ( otherwise_block, self . source_info ( expr_span) ) ;
2022
2023
2023
2024
if declare_bindings {
2024
- self . declare_bindings ( source_scope, pat. span . to ( span) , pat, None , opt_expr_place) ;
2025
+ let expr_place = scrutinee. try_to_place ( self ) ;
2026
+ let opt_expr_place = expr_place. as_ref ( ) . map ( |place| ( Some ( place) , expr_span) ) ;
2027
+ self . declare_bindings ( source_scope, pat. span . to ( scope_span) , pat, None , opt_expr_place) ;
2025
2028
}
2026
2029
2027
- let post_guard_block = self . bind_pattern (
2030
+ let success = self . bind_pattern (
2028
2031
self . source_info ( pat. span ) ,
2029
- guard_candidate ,
2032
+ candidate ,
2030
2033
& [ ] ,
2031
2034
expr_span,
2032
2035
None ,
2033
- false ,
2036
+ storages_alive ,
2034
2037
) ;
2035
2038
2036
2039
// If branch coverage is enabled, record this branch.
2037
- self . visit_coverage_conditional_let ( pat, post_guard_block , otherwise_block) ;
2040
+ self . visit_coverage_conditional_let ( pat, success , otherwise_block) ;
2038
2041
2039
- post_guard_block . unit ( )
2042
+ success . unit ( )
2040
2043
}
2041
2044
2042
2045
/// Initializes each of the bindings from the candidate by
@@ -2483,44 +2486,4 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2483
2486
debug ! ( ?locals) ;
2484
2487
self . var_indices . insert ( var_id, locals) ;
2485
2488
}
2486
-
2487
- pub ( crate ) fn ast_let_else (
2488
- & mut self ,
2489
- mut block : BasicBlock ,
2490
- init_id : ExprId ,
2491
- initializer_span : Span ,
2492
- else_block : BlockId ,
2493
- let_else_scope : & region:: Scope ,
2494
- pattern : & Pat < ' tcx > ,
2495
- ) -> BlockAnd < BasicBlock > {
2496
- let else_block_span = self . thir [ else_block] . span ;
2497
- let ( matching, failure) = self . in_if_then_scope ( * let_else_scope, else_block_span, |this| {
2498
- let scrutinee = unpack ! ( block = this. lower_scrutinee( block, init_id, initializer_span) ) ;
2499
- let mut candidate = Candidate :: new ( scrutinee. clone ( ) , pattern, false , this) ;
2500
- let failure_block = this. lower_match_tree (
2501
- block,
2502
- initializer_span,
2503
- & scrutinee,
2504
- pattern. span ,
2505
- & mut [ & mut candidate] ,
2506
- true ,
2507
- ) ;
2508
- // This block is for the matching case
2509
- let matching = this. bind_pattern (
2510
- this. source_info ( pattern. span ) ,
2511
- candidate,
2512
- & [ ] ,
2513
- initializer_span,
2514
- None ,
2515
- true ,
2516
- ) ;
2517
-
2518
- // If branch coverage is enabled, record this branch.
2519
- this. visit_coverage_conditional_let ( pattern, matching, failure_block) ;
2520
-
2521
- this. break_for_else ( failure_block, this. source_info ( initializer_span) ) ;
2522
- matching. unit ( )
2523
- } ) ;
2524
- matching. and ( failure)
2525
- }
2526
2489
}
0 commit comments