Skip to content

Commit 3402f39

Browse files
committed
Clarify lowering the else arm into the else block
1 parent 7396fd1 commit 3402f39

File tree

1 file changed

+6
-6
lines changed
  • compiler/rustc_mir_build/src/build/expr

1 file changed

+6
-6
lines changed

compiler/rustc_mir_build/src/build/expr/into.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9595
let (then_blk, mut else_blk);
9696
else_blk = unpack!(then_blk = then_and_else_blocks);
9797

98-
else_blk = if let Some(else_opt) = else_opt {
99-
unpack!(this.expr_into_dest(destination, else_blk, else_opt))
98+
// If there is an `else` arm, lower it into `else_blk`.
99+
if let Some(else_expr) = else_opt {
100+
unpack!(else_blk = this.expr_into_dest(destination, else_blk, else_expr));
100101
} else {
101-
// Body of the `if` expression without an `else` clause must return `()`, thus
102-
// we implicitly generate an `else {}` if it is not specified.
102+
// There is no `else` arm, so we know both arms have type `()`.
103+
// Generate the implicit `else {}` by assigning unit.
103104
let correct_si = this.source_info(expr_span.shrink_to_hi());
104105
this.cfg.push_assign_unit(else_blk, correct_si, destination, this.tcx);
105-
else_blk
106-
};
106+
}
107107

108108
let join_block = this.cfg.start_new_block();
109109
this.cfg.goto(then_blk, source_info, join_block);

0 commit comments

Comments
 (0)