@@ -547,15 +547,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
547547
548548 // Lowers a condition (i.e. `cond` in `if cond` or `while cond`), wrapping it in a terminating scope
549549 // 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-
550+ pub ( super ) fn lower_cond ( & mut self , cond : & Expr ) -> & ' hir hir:: Expr < ' hir > {
559551 // We have to take special care for `let` exprs in the condition, e.g. in
560552 // `if let pat = val` or `if foo && let pat = val`, as we _do_ want `val` to live beyond the
561553 // condition in this case.
@@ -564,14 +556,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
564556 // we still wrap them in terminating scopes, e.g. `if foo && let pat = val` essentially
565557 // gets transformed into `if { let _t = foo; _t } && let pat = val`
566558 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) ) )
559+ ExprKind :: Binary ( BinOp { node : BinOpKind :: And | BinOpKind :: Or , .. } , _, _) => {
560+ // Terminating scopes for logical `&&` and `||` are handled in
561+ // `rustc_hir_analysis::check::region::resolve_expr`; see the comment there.
562+ self . lower_expr ( cond)
575563 }
576564 ExprKind :: Let ( ..) => self . lower_expr ( cond) ,
577565 _ => {
@@ -675,7 +663,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
675663
676664 fn lower_arm ( & mut self , arm : & Arm ) -> hir:: Arm < ' hir > {
677665 let pat = self . lower_pat ( & arm. pat ) ;
678- let guard = arm. guard . as_ref ( ) . map ( |cond| self . lower_expr ( cond) ) ;
666+ let guard = arm. guard . as_ref ( ) . map ( |cond| self . lower_cond ( cond) ) ;
679667 let hir_id = self . next_id ( ) ;
680668 let span = self . lower_span ( arm. span ) ;
681669 self . lower_attrs ( hir_id, & arm. attrs , arm. span ) ;
0 commit comments