@@ -532,7 +532,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
532
532
then : & Block ,
533
533
else_opt : Option < & Expr > ,
534
534
) -> hir:: ExprKind < ' hir > {
535
- let lowered_cond = self . lower_cond ( cond) ;
535
+ let lowered_cond = self . lower_expr ( cond) ;
536
536
let then_expr = self . lower_block_expr ( then) ;
537
537
if let Some ( rslt) = else_opt {
538
538
hir:: ExprKind :: If (
@@ -545,44 +545,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
545
545
}
546
546
}
547
547
548
- // Lowers a condition (i.e. `cond` in `if cond` or `while cond`), wrapping it in a terminating scope
549
- // so that temporaries created in the condition don't live beyond it.
550
- fn lower_cond ( & mut self , cond : & Expr ) -> & ' hir hir:: Expr < ' hir > {
551
- fn has_let_expr ( expr : & Expr ) -> bool {
552
- match & expr. kind {
553
- ExprKind :: Binary ( _, lhs, rhs) => has_let_expr ( lhs) || has_let_expr ( rhs) ,
554
- ExprKind :: Let ( ..) => true ,
555
- _ => false ,
556
- }
557
- }
558
-
559
- // We have to take special care for `let` exprs in the condition, e.g. in
560
- // `if let pat = val` or `if foo && let pat = val`, as we _do_ want `val` to live beyond the
561
- // condition in this case.
562
- //
563
- // In order to maintain the drop behavior for the non `let` parts of the condition,
564
- // we still wrap them in terminating scopes, e.g. `if foo && let pat = val` essentially
565
- // gets transformed into `if { let _t = foo; _t } && let pat = val`
566
- match & cond. kind {
567
- ExprKind :: Binary ( op @ Spanned { node : ast:: BinOpKind :: And , .. } , lhs, rhs)
568
- if has_let_expr ( cond) =>
569
- {
570
- let op = self . lower_binop ( * op) ;
571
- let lhs = self . lower_cond ( lhs) ;
572
- let rhs = self . lower_cond ( rhs) ;
573
-
574
- self . arena . alloc ( self . expr ( cond. span , hir:: ExprKind :: Binary ( op, lhs, rhs) ) )
575
- }
576
- ExprKind :: Let ( ..) => self . lower_expr ( cond) ,
577
- _ => {
578
- let cond = self . lower_expr ( cond) ;
579
- let reason = DesugaringKind :: CondTemporary ;
580
- let span_block = self . mark_span_with_reason ( reason, cond. span , None ) ;
581
- self . expr_drop_temps ( span_block, cond)
582
- }
583
- }
584
- }
585
-
586
548
// We desugar: `'label: while $cond $body` into:
587
549
//
588
550
// ```
@@ -606,7 +568,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
606
568
body : & Block ,
607
569
opt_label : Option < Label > ,
608
570
) -> hir:: ExprKind < ' hir > {
609
- let lowered_cond = self . with_loop_condition_scope ( |t| t. lower_cond ( cond) ) ;
571
+ let lowered_cond = self . with_loop_condition_scope ( |t| t. lower_expr ( cond) ) ;
610
572
let then = self . lower_block_expr ( body) ;
611
573
let expr_break = self . expr_break ( span) ;
612
574
let stmt_break = self . stmt_expr ( span, expr_break) ;
@@ -2095,7 +2057,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
2095
2057
/// In terms of drop order, it has the same effect as wrapping `expr` in
2096
2058
/// `{ let _t = $expr; _t }` but should provide better compile-time performance.
2097
2059
///
2098
- /// The drop order can be important in e.g. `if expr { .. }`.
2060
+ /// The drop order can be important, e.g. to drop temporaries from an `async fn`
2061
+ /// body before its parameters.
2099
2062
pub ( super ) fn expr_drop_temps (
2100
2063
& mut self ,
2101
2064
span : Span ,
0 commit comments