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.rs45
1 files changed, 33 insertions, 12 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 85cc342c4..785895277 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -309,13 +309,13 @@ impl DefCollector<'_> {
309 let macro_def = match self.proc_macros.iter().find(|(n, _)| n == name) { 309 let macro_def = match self.proc_macros.iter().find(|(n, _)| n == name) {
310 Some((_, expander)) => MacroDefId { 310 Some((_, expander)) => MacroDefId {
311 ast_id: None, 311 ast_id: None,
312 krate: Some(self.def_map.krate), 312 krate: self.def_map.krate,
313 kind: MacroDefKind::ProcMacro(*expander), 313 kind: MacroDefKind::ProcMacro(*expander),
314 local_inner: false, 314 local_inner: false,
315 }, 315 },
316 None => MacroDefId { 316 None => MacroDefId {
317 ast_id: None, 317 ast_id: None,
318 krate: Some(self.def_map.krate), 318 krate: self.def_map.krate,
319 kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate)), 319 kind: MacroDefKind::ProcMacro(ProcMacroExpander::dummy(self.def_map.krate)),
320 local_inner: false, 320 local_inner: false,
321 }, 321 },
@@ -784,14 +784,6 @@ impl DefCollector<'_> {
784 directive: &DeriveDirective, 784 directive: &DeriveDirective,
785 path: &ModPath, 785 path: &ModPath,
786 ) -> Option<MacroDefId> { 786 ) -> Option<MacroDefId> {
787 if let Some(name) = path.as_ident() {
788 // FIXME this should actually be handled with the normal name
789 // resolution; the std lib defines built-in stubs for the derives,
790 // but these are new-style `macro`s, which we don't support yet
791 if let Some(def_id) = find_builtin_derive(name) {
792 return Some(def_id);
793 }
794 }
795 let resolved_res = self.def_map.resolve_path_fp_with_macro( 787 let resolved_res = self.def_map.resolve_path_fp_with_macro(
796 self.db, 788 self.db,
797 ResolveMode::Other, 789 ResolveMode::Other,
@@ -976,6 +968,35 @@ impl ModCollector<'_, '_> {
976 } 968 }
977 ModItem::MacroCall(mac) => self.collect_macro_call(&self.item_tree[mac]), 969 ModItem::MacroCall(mac) => self.collect_macro_call(&self.item_tree[mac]),
978 ModItem::MacroRules(mac) => self.collect_macro_rules(&self.item_tree[mac]), 970 ModItem::MacroRules(mac) => self.collect_macro_rules(&self.item_tree[mac]),
971 ModItem::MacroDef(id) => {
972 let mac = &self.item_tree[id];
973 let ast_id = InFile::new(self.file_id, mac.ast_id.upcast());
974
975 // "Macro 2.0" is not currently supported by rust-analyzer, but libcore uses it
976 // to define builtin macros, so we support at least that part.
977 if mac.is_builtin {
978 let krate = self.def_collector.def_map.krate;
979 let macro_id = find_builtin_macro(&mac.name, krate, ast_id)
980 .or_else(|| find_builtin_derive(&mac.name, krate, ast_id));
981 if let Some(macro_id) = macro_id {
982 let vis = self
983 .def_collector
984 .def_map
985 .resolve_visibility(
986 self.def_collector.db,
987 self.module_id,
988 &self.item_tree[mac.visibility],
989 )
990 .unwrap_or(Visibility::Public);
991 self.def_collector.update(
992 self.module_id,
993 &[(Some(mac.name.clone()), PerNs::macros(macro_id, vis))],
994 vis,
995 ImportType::Named,
996 );
997 }
998 }
999 }
979 ModItem::Impl(imp) => { 1000 ModItem::Impl(imp) => {
980 let module = ModuleId { 1001 let module = ModuleId {
981 krate: self.def_collector.def_map.krate, 1002 krate: self.def_collector.def_map.krate,
@@ -1280,7 +1301,7 @@ impl ModCollector<'_, '_> {
1280 } 1301 }
1281 1302
1282 fn collect_macro_rules(&mut self, mac: &MacroRules) { 1303 fn collect_macro_rules(&mut self, mac: &MacroRules) {
1283 let ast_id = InFile::new(self.file_id, mac.ast_id); 1304 let ast_id = InFile::new(self.file_id, mac.ast_id.upcast());
1284 1305
1285 // Case 1: builtin macros 1306 // Case 1: builtin macros
1286 if mac.is_builtin { 1307 if mac.is_builtin {
@@ -1299,7 +1320,7 @@ impl ModCollector<'_, '_> {
1299 // Case 2: normal `macro_rules!` macro 1320 // Case 2: normal `macro_rules!` macro
1300 let macro_id = MacroDefId { 1321 let macro_id = MacroDefId {
1301 ast_id: Some(ast_id), 1322 ast_id: Some(ast_id),
1302 krate: Some(self.def_collector.def_map.krate), 1323 krate: self.def_collector.def_map.krate,
1303 kind: MacroDefKind::Declarative, 1324 kind: MacroDefKind::Declarative,
1304 local_inner: mac.is_local_inner, 1325 local_inner: mac.is_local_inner,
1305 }; 1326 };