diff options
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 13 |
1 files changed, 7 insertions, 6 deletions
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<'_> { | |||
353 | /// use a dummy expander that always errors. This comes with the drawback of macros potentially | 353 | /// use a dummy expander that always errors. This comes with the drawback of macros potentially |
354 | /// going out of sync with what the build system sees (since we resolve using VFS state, but | 354 | /// going out of sync with what the build system sees (since we resolve using VFS state, but |
355 | /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. | 355 | /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. |
356 | fn resolve_proc_macro(&mut self, name: &Name) { | 356 | fn resolve_proc_macro(&mut self, name: &Name, ast_id: AstId<ast::Fn>) { |
357 | self.exports_proc_macros = true; | 357 | self.exports_proc_macros = true; |
358 | let macro_def = match self.proc_macros.iter().find(|(n, _)| n == name) { | 358 | let macro_def = match self.proc_macros.iter().find(|(n, _)| n == name) { |
359 | Some((_, expander)) => MacroDefId { | 359 | Some((_, expander)) => MacroDefId { |
360 | krate: self.def_map.krate, | 360 | krate: self.def_map.krate, |
361 | kind: MacroDefKind::ProcMacro(*expander), | 361 | kind: MacroDefKind::ProcMacro(*expander, ast_id), |
362 | local_inner: false, | 362 | local_inner: false, |
363 | }, | 363 | }, |
364 | None => MacroDefId { | 364 | None => MacroDefId { |
365 | krate: self.def_map.krate, | 365 | krate: self.def_map.krate, |
366 | kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate)), | 366 | kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate), ast_id), |
367 | local_inner: false, | 367 | local_inner: false, |
368 | }, | 368 | }, |
369 | }; | 369 | }; |
@@ -1116,7 +1116,8 @@ impl ModCollector<'_, '_> { | |||
1116 | ModItem::Function(id) => { | 1116 | ModItem::Function(id) => { |
1117 | let func = &self.item_tree[id]; | 1117 | let func = &self.item_tree[id]; |
1118 | 1118 | ||
1119 | self.collect_proc_macro_def(&func.name, &attrs); | 1119 | let ast_id = InFile::new(self.file_id, func.ast_id); |
1120 | self.collect_proc_macro_def(&func.name, ast_id, &attrs); | ||
1120 | 1121 | ||
1121 | def = Some(DefData { | 1122 | def = Some(DefData { |
1122 | id: FunctionLoc { | 1123 | id: FunctionLoc { |
@@ -1383,7 +1384,7 @@ impl ModCollector<'_, '_> { | |||
1383 | } | 1384 | } |
1384 | 1385 | ||
1385 | /// If `attrs` registers a procedural macro, collects its definition. | 1386 | /// If `attrs` registers a procedural macro, collects its definition. |
1386 | fn collect_proc_macro_def(&mut self, func_name: &Name, attrs: &Attrs) { | 1387 | fn collect_proc_macro_def(&mut self, func_name: &Name, ast_id: AstId<ast::Fn>, attrs: &Attrs) { |
1387 | // FIXME: this should only be done in the root module of `proc-macro` crates, not everywhere | 1388 | // FIXME: this should only be done in the root module of `proc-macro` crates, not everywhere |
1388 | // FIXME: distinguish the type of macro | 1389 | // FIXME: distinguish the type of macro |
1389 | let macro_name = if attrs.by_key("proc_macro").exists() | 1390 | let macro_name = if attrs.by_key("proc_macro").exists() |
@@ -1404,7 +1405,7 @@ impl ModCollector<'_, '_> { | |||
1404 | } | 1405 | } |
1405 | }; | 1406 | }; |
1406 | 1407 | ||
1407 | self.def_collector.resolve_proc_macro(¯o_name); | 1408 | self.def_collector.resolve_proc_macro(¯o_name, ast_id); |
1408 | } | 1409 | } |
1409 | 1410 | ||
1410 | fn collect_macro_rules(&mut self, id: FileItemTreeId<MacroRules>) { | 1411 | fn collect_macro_rules(&mut self, id: FileItemTreeId<MacroRules>) { |