about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-03-06 15:22:39 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-03-06 17:08:28 +1100
commit250e697834b2c48db7f71d9f2926eda51f3486a6 (patch)
tree381dfe9faf338a9b237f202b363507cc9f005394 /compiler
parent3402f39bcb684fd2edf9e7cae21b1ae68c720886 (diff)
downloadrust-250e697834b2c48db7f71d9f2926eda51f3486a6.tar.gz
rust-250e697834b2c48db7f71d9f2926eda51f3486a6.zip
Additional comments for lowering `if`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_mir_build/src/build/expr/into.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs
index 7e1a066e105..69f3d3101fa 100644
--- a/compiler/rustc_mir_build/src/build/expr/into.rs
+++ b/compiler/rustc_mir_build/src/build/expr/into.rs
@@ -66,6 +66,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     (if_then_scope, then_source_info),
                     LintLevel::Inherited,
                     |this| {
+                        // FIXME: Does this need extra logic to handle let-chains?
                         let source_info = if this.is_let(cond) {
                             let variable_scope =
                                 this.new_source_scope(then_span, LintLevel::Inherited, None);
@@ -74,6 +75,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                         } else {
                             this.source_info(then_span)
                         };
+
+                        // Lower the condition, and have it branch into `then` and `else` blocks.
                         let (then_block, else_block) =
                             this.in_if_then_scope(condition_scope, then_span, |this| {
                                 let then_blk = unpack!(this.then_else_break(
@@ -85,8 +88,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                                     true, // Declare `let` bindings normally
                                 ));
 
+                                // Lower the `then` arm into its block.
                                 this.expr_into_dest(destination, then_blk, then)
                             });
+
+                        // Pack `(then_block, else_block)` into `BlockAnd<BasicBlock>`.
                         then_block.and(else_block)
                     },
                 );
@@ -105,6 +111,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     this.cfg.push_assign_unit(else_blk, correct_si, destination, this.tcx);
                 }
 
+                // The `then` and `else` arms have been lowered into their respective
+                // blocks, so make both of them meet up in a new block.
                 let join_block = this.cfg.start_new_block();
                 this.cfg.goto(then_blk, source_info, join_block);
                 this.cfg.goto(else_blk, source_info, join_block);