diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-03-06 15:11:21 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-03-06 17:08:28 +1100 |
| commit | 3402f39bcb684fd2edf9e7cae21b1ae68c720886 (patch) | |
| tree | 6bf07eb478b4a72f07a9fc1784c3f56acef057ad | |
| parent | 7396fd1fa06f0dd0ce0c8c92783736420e154495 (diff) | |
| download | rust-3402f39bcb684fd2edf9e7cae21b1ae68c720886.tar.gz rust-3402f39bcb684fd2edf9e7cae21b1ae68c720886.zip | |
Clarify lowering the `else` arm into the else block
| -rw-r--r-- | compiler/rustc_mir_build/src/build/expr/into.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 8440db208e7..7e1a066e105 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -95,15 +95,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let (then_blk, mut else_blk); else_blk = unpack!(then_blk = then_and_else_blocks); - else_blk = if let Some(else_opt) = else_opt { - unpack!(this.expr_into_dest(destination, else_blk, else_opt)) + // If there is an `else` arm, lower it into `else_blk`. + if let Some(else_expr) = else_opt { + unpack!(else_blk = this.expr_into_dest(destination, else_blk, else_expr)); } else { - // Body of the `if` expression without an `else` clause must return `()`, thus - // we implicitly generate an `else {}` if it is not specified. + // There is no `else` arm, so we know both arms have type `()`. + // Generate the implicit `else {}` by assigning unit. let correct_si = this.source_info(expr_span.shrink_to_hi()); this.cfg.push_assign_unit(else_blk, correct_si, destination, this.tcx); - else_blk - }; + } let join_block = this.cfg.start_new_block(); this.cfg.goto(then_blk, source_info, join_block); |
