@@ -532,7 +532,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
532532 then : & Block ,
533533 else_opt : Option < & Expr > ,
534534 ) -> hir:: ExprKind < ' hir > {
535- let lowered_cond = self . lower_cond ( cond) ;
535+ let lowered_cond = self . lower_expr ( cond) ;
536536 let then_expr = self . lower_block_expr ( then) ;
537537 if let Some ( rslt) = else_opt {
538538 hir:: ExprKind :: If (
@@ -545,44 +545,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
545545 }
546546 }
547547
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-
586548 // We desugar: `'label: while $cond $body` into:
587549 //
588550 // ```
@@ -606,7 +568,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
606568 body : & Block ,
607569 opt_label : Option < Label > ,
608570 ) -> 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) ) ;
610572 let then = self . lower_block_expr ( body) ;
611573 let expr_break = self . expr_break ( span) ;
612574 let stmt_break = self . stmt_expr ( span, expr_break) ;
@@ -2095,7 +2057,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
20952057 /// In terms of drop order, it has the same effect as wrapping `expr` in
20962058 /// `{ let _t = $expr; _t }` but should provide better compile-time performance.
20972059 ///
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.
20992062 pub ( super ) fn expr_drop_temps (
21002063 & mut self ,
21012064 span : Span ,
0 commit comments