From c05a1a6e37156b956380d57049a72cfe6f21095d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 18 Mar 2021 16:11:18 +0100 Subject: Store an `AstId` for procedural macros --- crates/hir_def/src/item_scope.rs | 2 +- crates/hir_def/src/nameres/collector.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/item_scope.rs b/crates/hir_def/src/item_scope.rs index aafd73b60..f3ebe7c72 100644 --- a/crates/hir_def/src/item_scope.rs +++ b/crates/hir_def/src/item_scope.rs @@ -252,7 +252,7 @@ impl ItemScope { .for_each(|vis| *vis = Visibility::Module(this_module)); for (mac, vis) in self.macros.values_mut() { - if let MacroDefKind::ProcMacro(_) = mac.kind { + if let MacroDefKind::ProcMacro(..) = mac.kind { // FIXME: Technically this is insufficient since reexports of proc macros are also // forbidden. Practically nobody does that. continue; diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 45a79e896..696370ada 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -353,17 +353,17 @@ impl DefCollector<'_> { /// use a dummy expander that always errors. This comes with the drawback of macros potentially /// going out of sync with what the build system sees (since we resolve using VFS state, but /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. - fn resolve_proc_macro(&mut self, name: &Name) { + fn resolve_proc_macro(&mut self, name: &Name, ast_id: AstId) { self.exports_proc_macros = true; let macro_def = match self.proc_macros.iter().find(|(n, _)| n == name) { Some((_, expander)) => MacroDefId { krate: self.def_map.krate, - kind: MacroDefKind::ProcMacro(*expander), + kind: MacroDefKind::ProcMacro(*expander, ast_id), local_inner: false, }, None => MacroDefId { krate: self.def_map.krate, - kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate)), + kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate), ast_id), local_inner: false, }, }; @@ -1116,7 +1116,8 @@ impl ModCollector<'_, '_> { ModItem::Function(id) => { let func = &self.item_tree[id]; - self.collect_proc_macro_def(&func.name, &attrs); + let ast_id = InFile::new(self.file_id, func.ast_id); + self.collect_proc_macro_def(&func.name, ast_id, &attrs); def = Some(DefData { id: FunctionLoc { @@ -1383,7 +1384,7 @@ impl ModCollector<'_, '_> { } /// If `attrs` registers a procedural macro, collects its definition. - fn collect_proc_macro_def(&mut self, func_name: &Name, attrs: &Attrs) { + fn collect_proc_macro_def(&mut self, func_name: &Name, ast_id: AstId, attrs: &Attrs) { // FIXME: this should only be done in the root module of `proc-macro` crates, not everywhere // FIXME: distinguish the type of macro let macro_name = if attrs.by_key("proc_macro").exists() @@ -1404,7 +1405,7 @@ impl ModCollector<'_, '_> { } }; - self.def_collector.resolve_proc_macro(¯o_name); + self.def_collector.resolve_proc_macro(¯o_name, ast_id); } fn collect_macro_rules(&mut self, id: FileItemTreeId) { -- cgit v1.2.3