Compute parent module when collecting hir::MacroDef.

This commit is contained in:
Camille GILLOT 2020-12-27 17:57:17 +01:00
parent 68ec332611
commit 59f1ccd35c
1 changed files with 16 additions and 7 deletions

View File

@ -529,13 +529,22 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
} }
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) { fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) {
self.with_dep_node_owner(macro_def.hir_id.owner, macro_def, |this, hash| { // Exported macros are visited directly from the crate root,
this.insert_with_hash( // so they do not have `parent_node` set.
macro_def.span, // Find the correct enclosing module from their DefKey.
macro_def.hir_id, let def_key = self.definitions.def_key(macro_def.hir_id.owner);
Node::MacroDef(macro_def), let parent = def_key.parent.map_or(hir::CRATE_HIR_ID, |local_def_index| {
hash, self.definitions.local_def_id_to_hir_id(LocalDefId { local_def_index })
); });
self.with_parent(parent, |this| {
this.with_dep_node_owner(macro_def.hir_id.owner, macro_def, |this, hash| {
this.insert_with_hash(
macro_def.span,
macro_def.hir_id,
Node::MacroDef(macro_def),
hash,
);
})
}); });
} }