Skip to content

Commit c7d1c9b

Browse files
add explanatory note
1 parent 635b57c commit c7d1c9b

File tree

1 file changed

+15
-0
lines changed
  • compiler/rustc_mir_build/src/build

1 file changed

+15
-0
lines changed

compiler/rustc_mir_build/src/build/block.rs

+15
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
117117
lint_level,
118118
else_block: Some(else_block),
119119
} => {
120+
// When lowering the statement `let <pat> = <expr> else { <else> };`,
121+
// the `<else>` block is nested in the parent scope enclosing this statment.
122+
// That scope is usually either the enclosing block scope,
123+
// or the remainder scope of the last statement.
124+
// This is to make sure that temporaries instantiated in `<expr>` are dropped
125+
// as well.
126+
// In addition, even though bindings in `<pat>` only come into scope if
127+
// the pattern matching passes, in the MIR building the storages for them
128+
// are declared as live any way.
129+
// This is similar to `let x;` statements without an initializer expression,
130+
// where the value of `x` in this example may or may be assigned,
131+
// because the storage for their values may not be live after all due to
132+
// failure in pattern matching.
133+
// For this reason, we declare those storages as live but we do not schedule
134+
// any drop yet- they are scheduled later after the pattern matching.
120135
let ignores_expr_result = matches!(pattern.kind, PatKind::Wild);
121136
this.block_context.push(BlockFrame::Statement { ignores_expr_result });
122137

0 commit comments

Comments
 (0)