]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/build/expr/into.rs
Remove ExprKind::While from HIR.
[rust.git] / src / librustc_mir / build / expr / into.rs
index f70ecef0c254a0fd03b964aa1146626e572910ee..e433da904a67877bd22a318ae5094ec104b21f68 100644 (file)
@@ -138,19 +138,7 @@ pub fn into_expr(
 
                 join_block.unit()
             }
-            ExprKind::Loop {
-                condition: opt_cond_expr,
-                body,
-            } => {
-                // [block] --> [loop_block] -/eval. cond./-> [loop_block_end] -1-> [exit_block]
-                //                  ^                               |
-                //                  |                               0
-                //                  |                               |
-                //                  |                               v
-                //           [body_block_end] <-/eval. body/-- [body_block]
-                //
-                // If `opt_cond_expr` is `None`, then the graph is somewhat simplified:
-                //
+            ExprKind::Loop { body } => {
                 // [block]
                 //    |
                 //   [loop_block] -> [body_block] -/eval. body/-> [body_block_end]
@@ -177,34 +165,16 @@ pub fn into_expr(
                     destination.clone(),
                     move |this| {
                         // conduct the test, if necessary
-                        let body_block;
-                        if let Some(cond_expr) = opt_cond_expr {
-                            let loop_block_end;
-                            let cond = unpack!(
-                                loop_block_end = this.as_local_operand(loop_block, cond_expr)
-                            );
-                            body_block = this.cfg.start_new_block();
-                            let term =
-                                TerminatorKind::if_(this.hir.tcx(), cond, body_block, exit_block);
-                            this.cfg.terminate(loop_block_end, source_info, term);
-
-                            // if the test is false, there's no `break` to assign `destination`, so
-                            // we have to do it; this overwrites any `break`-assigned value but it's
-                            // always `()` anyway
-                            this.cfg
-                                .push_assign_unit(exit_block, source_info, destination);
-                        } else {
-                            body_block = this.cfg.start_new_block();
-                            let diverge_cleanup = this.diverge_cleanup();
-                            this.cfg.terminate(
-                                loop_block,
-                                source_info,
-                                TerminatorKind::FalseUnwind {
-                                    real_target: body_block,
-                                    unwind: Some(diverge_cleanup),
-                                },
-                            )
-                        }
+                        let body_block = this.cfg.start_new_block();
+                        let diverge_cleanup = this.diverge_cleanup();
+                        this.cfg.terminate(
+                            loop_block,
+                            source_info,
+                            TerminatorKind::FalseUnwind {
+                                real_target: body_block,
+                                unwind: Some(diverge_cleanup),
+                            },
+                        );
 
                         // The “return” value of the loop body must always be an unit. We therefore
                         // introduce a unit temporary as the destination for the loop body.