@@ -547,15 +547,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
547
547
548
548
// Lowers a condition (i.e. `cond` in `if cond` or `while cond`), wrapping it in a terminating scope
549
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
-
550
+ pub ( super ) fn lower_cond ( & mut self , cond : & Expr ) -> & ' hir hir:: Expr < ' hir > {
559
551
// We have to take special care for `let` exprs in the condition, e.g. in
560
552
// `if let pat = val` or `if foo && let pat = val`, as we _do_ want `val` to live beyond the
561
553
// condition in this case.
@@ -564,14 +556,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
564
556
// we still wrap them in terminating scopes, e.g. `if foo && let pat = val` essentially
565
557
// gets transformed into `if { let _t = foo; _t } && let pat = val`
566
558
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)
575
563
}
576
564
ExprKind :: Let ( ..) => self . lower_expr ( cond) ,
577
565
_ => {
@@ -675,7 +663,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
675
663
676
664
fn lower_arm ( & mut self , arm : & Arm ) -> hir:: Arm < ' hir > {
677
665
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) ) ;
679
667
let hir_id = self . next_id ( ) ;
680
668
let span = self . lower_span ( arm. span ) ;
681
669
self . lower_attrs ( hir_id, & arm. attrs , arm. span ) ;
0 commit comments