Skip to content

Commit 74be945

Browse files
committed
Expand comment in with_hir_id_owner.
1 parent 15530a1 commit 74be945

File tree

1 file changed

+9
-2
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+9
-2
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
491491
self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node))
492492
}
493493

494+
/// Freshen the `LoweringContext` and ready it to lower a nested item.
495+
/// The lowered item is registered into `self.children`.
496+
///
497+
/// This function sets up `HirId` lowering infrastructure,
498+
/// and stashes the shared mutable state to avoid pollution by the closure.
494499
#[instrument(level = "debug", skip(self, f))]
495500
fn with_hir_id_owner(
496501
&mut self,
@@ -509,8 +514,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
509514
std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
510515
let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
511516
let current_impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
512-
// Do not reset `next_node_id` and `node_id_to_def_id` as we want to refer to the
513-
// subdefinitions' nodes.
517+
518+
// Do not reset `next_node_id` and `node_id_to_def_id`:
519+
// we want `f` to be able to refer to the `LocalDefId`s that the caller created.
520+
// and the caller to refer to some of the subdefinitions' nodes' `LocalDefId`s.
514521

515522
// Always allocate the first `HirId` for the owner itself.
516523
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::new(0));

0 commit comments

Comments
 (0)