Skip to content

Commit 96d9369

Browse files
committed
document move expression lowering bindings
1 parent f6abfa6 commit 96d9369

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • compiler/rustc_ast_lowering/src

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
252252
if !self.tcx.features().move_expr() {
253253
return self.expr_err(*move_kw_span, self.dcx().has_errors().unwrap());
254254
}
255+
// `last()` selects the binding map for the closure body currently
256+
// being lowered. The map is keyed by the AST `NodeId`, so `e.id`
257+
// selects the synthetic local for this exact `move(...)` occurrence.
255258
if let Some((ident, binding)) = self
256259
.move_expr_bindings
257260
.last()
@@ -1165,6 +1168,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
11651168
lowered_occurrences.push((occurrence, pat, binding));
11661169
}
11671170

1171+
// During body lowering, replace each `move(...)` occurrence with the
1172+
// synthetic local recorded in this closure's binding map. Nested closures
1173+
// push their own maps.
11681174
self.move_expr_bindings.push(bindings);
11691175
let mut stmts = Vec::with_capacity(lowered_occurrences.len());
11701176
for (occurrence, pat, _) in &lowered_occurrences {
@@ -1201,6 +1207,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
12011207
),
12021208
span: self.lower_span(whole_span),
12031209
});
1210+
// Restore the enclosing closure's substitution map before lowering the
1211+
// block that contains the synthetic `let`s.
12041212
self.move_expr_bindings.pop();
12051213

12061214
let stmts = self.arena.alloc_from_iter(stmts);

0 commit comments

Comments
 (0)