Skip to content

Commit

Permalink
Additional comments for lowering if
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Mar 6, 2024
1 parent 3402f39 commit 250e697
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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)
},
);
Expand All @@ -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);
Expand Down

0 comments on commit 250e697

Please sign in to comment.