aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres/collector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/nameres/collector.rs')
-rw-r--r--crates/hir_def/src/nameres/collector.rs57
1 files changed, 39 insertions, 18 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 716dcf1f7..7f9fdb379 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -477,16 +477,21 @@ impl DefCollector<'_> {
477 /// going out of sync with what the build system sees (since we resolve using VFS state, but 477 /// going out of sync with what the build system sees (since we resolve using VFS state, but
478 /// Cargo builds only on-disk files). We could and probably should add diagnostics for that. 478 /// Cargo builds only on-disk files). We could and probably should add diagnostics for that.
479 fn export_proc_macro(&mut self, def: ProcMacroDef, ast_id: AstId<ast::Fn>) { 479 fn export_proc_macro(&mut self, def: ProcMacroDef, ast_id: AstId<ast::Fn>) {
480 let kind = def.kind.to_basedb_kind();
480 self.exports_proc_macros = true; 481 self.exports_proc_macros = true;
481 let macro_def = match self.proc_macros.iter().find(|(n, _)| n == &def.name) { 482 let macro_def = match self.proc_macros.iter().find(|(n, _)| n == &def.name) {
482 Some((_, expander)) => MacroDefId { 483 Some((_, expander)) => MacroDefId {
483 krate: self.def_map.krate, 484 krate: self.def_map.krate,
484 kind: MacroDefKind::ProcMacro(*expander, ast_id), 485 kind: MacroDefKind::ProcMacro(*expander, kind, ast_id),
485 local_inner: false, 486 local_inner: false,
486 }, 487 },
487 None => MacroDefId { 488 None => MacroDefId {
488 krate: self.def_map.krate, 489 krate: self.def_map.krate,
489 kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate), ast_id), 490 kind: MacroDefKind::ProcMacro(
491 ProcMacroExpander::dummy(self.def_map.krate),
492 kind,
493 ast_id,
494 ),
490 local_inner: false, 495 local_inner: false,
491 }, 496 },
492 }; 497 };
@@ -1674,14 +1679,22 @@ impl ModCollector<'_, '_> {
1674 None => &mac.name, 1679 None => &mac.name,
1675 }; 1680 };
1676 let krate = self.def_collector.def_map.krate; 1681 let krate = self.def_collector.def_map.krate;
1677 if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) { 1682 match find_builtin_macro(name, krate, ast_id) {
1678 self.def_collector.define_macro_rules( 1683 Some(macro_id) => {
1679 self.module_id, 1684 self.def_collector.define_macro_rules(
1680 mac.name.clone(), 1685 self.module_id,
1681 macro_id, 1686 mac.name.clone(),
1682 is_export, 1687 macro_id,
1683 ); 1688 is_export,
1684 return; 1689 );
1690 return;
1691 }
1692 None => {
1693 self.def_collector
1694 .def_map
1695 .diagnostics
1696 .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id));
1697 }
1685 } 1698 }
1686 } 1699 }
1687 1700
@@ -1710,15 +1723,23 @@ impl ModCollector<'_, '_> {
1710 let macro_id = find_builtin_macro(&mac.name, krate, ast_id) 1723 let macro_id = find_builtin_macro(&mac.name, krate, ast_id)
1711 .or_else(|| find_builtin_derive(&mac.name, krate, ast_id)); 1724 .or_else(|| find_builtin_derive(&mac.name, krate, ast_id));
1712 1725
1713 if let Some(macro_id) = macro_id { 1726 match macro_id {
1714 self.def_collector.define_macro_def( 1727 Some(macro_id) => {
1715 self.module_id, 1728 self.def_collector.define_macro_def(
1716 mac.name.clone(), 1729 self.module_id,
1717 macro_id, 1730 mac.name.clone(),
1718 &self.item_tree[mac.visibility], 1731 macro_id,
1719 ); 1732 &self.item_tree[mac.visibility],
1733 );
1734 return;
1735 }
1736 None => {
1737 self.def_collector
1738 .def_map
1739 .diagnostics
1740 .push(DefDiagnostic::unimplemented_builtin_macro(self.module_id, ast_id));
1741 }
1720 } 1742 }
1721 return;
1722 } 1743 }
1723 1744
1724 // Case 2: normal `macro` 1745 // Case 2: normal `macro`