about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir_build/src/build/expr/into.rs68
-rw-r--r--tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs3
-rw-r--r--tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr13
3 files changed, 31 insertions, 53 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs
index a5c86e31a29..aecab5635aa 100644
--- a/compiler/rustc_mir_build/src/build/expr/into.rs
+++ b/compiler/rustc_mir_build/src/build/expr/into.rs
@@ -158,53 +158,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     end_block.unit()
                 }
             }
-            ExprKind::LogicalOp { op, lhs, rhs } => {
-                // And:
-                //
-                // [block: If(lhs)] -true-> [else_block: dest = (rhs)]
-                //        | (false)
-                //  [shortcircuit_block: dest = false]
-                //
-                // Or:
-                //
-                // [block: If(lhs)] -false-> [else_block: dest = (rhs)]
-                //        | (true)
-                //  [shortcircuit_block: dest = true]
-
-                let (shortcircuit_block, mut else_block, join_block) = (
-                    this.cfg.start_new_block(),
-                    this.cfg.start_new_block(),
-                    this.cfg.start_new_block(),
+            ExprKind::LogicalOp { .. } => {
+                let condition_scope = this.local_scope();
+                let source_info = this.source_info(expr.span);
+                let (then_block, else_block) =
+                    this.in_if_then_scope(condition_scope, expr.span, |this| {
+                        this.then_else_break(
+                            block,
+                            expr,
+                            Some(condition_scope),
+                            condition_scope,
+                            source_info,
+                        )
+                    });
+                this.cfg.push_assign_constant(
+                    then_block,
+                    source_info,
+                    destination,
+                    Constant {
+                        span: expr.span,
+                        user_ty: None,
+                        literal: ConstantKind::from_bool(this.tcx, true),
+                    },
                 );
-
-                let lhs = unpack!(block = this.as_local_operand(block, &this.thir[lhs]));
-                let blocks = match op {
-                    LogicalOp::And => (else_block, shortcircuit_block),
-                    LogicalOp::Or => (shortcircuit_block, else_block),
-                };
-                let term = TerminatorKind::if_(lhs, blocks.0, blocks.1);
-                this.cfg.terminate(block, source_info, term);
-
                 this.cfg.push_assign_constant(
-                    shortcircuit_block,
+                    else_block,
                     source_info,
                     destination,
                     Constant {
-                        span: expr_span,
+                        span: expr.span,
                         user_ty: None,
-                        literal: match op {
-                            LogicalOp::And => ConstantKind::from_bool(this.tcx, false),
-                            LogicalOp::Or => ConstantKind::from_bool(this.tcx, true),
-                        },
+                        literal: ConstantKind::from_bool(this.tcx, false),
                     },
                 );
-                this.cfg.goto(shortcircuit_block, source_info, join_block);
-
-                let rhs = unpack!(else_block = this.as_local_operand(else_block, &this.thir[rhs]));
-                this.cfg.push_assign(else_block, source_info, destination, Rvalue::Use(rhs));
-                this.cfg.goto(else_block, source_info, join_block);
-
-                join_block.unit()
+                let target = this.cfg.start_new_block();
+                this.cfg.goto(then_block, source_info, target);
+                this.cfg.goto(else_block, source_info, target);
+                target.unit()
             }
             ExprKind::Loop { body } => {
                 // [block]
diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs
index 484c1862839..2c0571a7bdd 100644
--- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs
+++ b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.rs
@@ -1,3 +1,5 @@
+// check-pass
+
 fn and_chain() {
     let z;
     if true && { z = 3; true} && z == 3 {}
@@ -6,7 +8,6 @@ fn and_chain() {
 fn and_chain_2() {
     let z;
     true && { z = 3; true} && z == 3;
-    //~^ ERROR E0381
 }
 
 fn or_chain() {
diff --git a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr b/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr
deleted file mode 100644
index 6bce7772bcc..00000000000
--- a/tests/ui/rfcs/rfc-2497-if-let-chains/chains-without-let.stderr
+++ /dev/null
@@ -1,13 +0,0 @@
-error[E0381]: used binding `z` is possibly-uninitialized
-  --> $DIR/chains-without-let.rs:8:31
-   |
-LL |     let z;
-   |         - binding declared here but left uninitialized
-LL |     true && { z = 3; true} && z == 3;
-   |               -----           ^ `z` used here but it is possibly-uninitialized
-   |               |
-   |               binding initialized here in some conditions
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0381`.