Skip to content

Commit 34f0c45

Browse files
supplement for the missing or incomplete comments
1 parent af591eb commit 34f0c45

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

compiler/rustc_mir_build/src/build/block.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
119119
} => {
120120
let ignores_expr_result = matches!(pattern.kind, PatKind::Wild);
121121
this.block_context.push(BlockFrame::Statement { ignores_expr_result });
122+
123+
// Lower the `else` block first because its parent scope is actually
124+
// enclosing the rest of the `let .. else ..` parts.
125+
let else_block_span = this.thir[*else_block].span;
122126
// This place is not really used because this destination place
123127
// should never be used to take values at the end of the failure
124128
// block.
125-
let else_block_span = this.thir[*else_block].span;
126129
let dummy_place = this.temp(this.tcx.types.never, else_block_span);
127130
let failure_entry = this.cfg.start_new_block();
128131
let failure_block;

compiler/rustc_typeck/src/check/region.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,24 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
128128
match statement.kind {
129129
hir::StmtKind::Local(hir::Local { els: Some(els), .. }) => {
130130
// Let-else has a special lexical structure for variables.
131+
// First we take a checkpoint of the current scope context here.
131132
let mut prev_cx = visitor.cx;
133+
132134
visitor.enter_scope(Scope {
133135
id: blk.hir_id.local_id,
134136
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
135137
});
136138
visitor.cx.var_parent = visitor.cx.parent;
137139
visitor.visit_stmt(statement);
140+
// We need to back out temporarily to the last enclosing scope
141+
// for the `else` block, so that even the temporaries receiving
142+
// extended lifetime will be dropped inside this block.
143+
// We are visiting the `else` block in this order so that
144+
// the sequence of visits agree with the order in the default
145+
// `hir::intravisit` visitor.
138146
mem::swap(&mut prev_cx, &mut visitor.cx);
139-
// We need to back out temporarily and
140147
visitor.visit_block(els);
148+
// From now on, we continue normally.
141149
visitor.cx = prev_cx;
142150
}
143151
hir::StmtKind::Local(..) | hir::StmtKind::Item(..) => {

0 commit comments

Comments
 (0)