diff options
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 85cc342c4..c2f741060 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -976,6 +976,33 @@ impl ModCollector<'_, '_> { | |||
976 | } | 976 | } |
977 | ModItem::MacroCall(mac) => self.collect_macro_call(&self.item_tree[mac]), | 977 | ModItem::MacroCall(mac) => self.collect_macro_call(&self.item_tree[mac]), |
978 | ModItem::MacroRules(mac) => self.collect_macro_rules(&self.item_tree[mac]), | 978 | ModItem::MacroRules(mac) => self.collect_macro_rules(&self.item_tree[mac]), |
979 | ModItem::MacroDef(id) => { | ||
980 | let mac = &self.item_tree[id]; | ||
981 | let ast_id = InFile::new(self.file_id, mac.ast_id.upcast()); | ||
982 | |||
983 | // "Macro 2.0" is not currently supported by rust-analyzer, but libcore uses it | ||
984 | // to define builtin macros, so we support at least that part. | ||
985 | if mac.is_builtin { | ||
986 | let krate = self.def_collector.def_map.krate; | ||
987 | if let Some(macro_id) = find_builtin_macro(&mac.name, krate, ast_id) { | ||
988 | let vis = self | ||
989 | .def_collector | ||
990 | .def_map | ||
991 | .resolve_visibility( | ||
992 | self.def_collector.db, | ||
993 | self.module_id, | ||
994 | &self.item_tree[mac.visibility], | ||
995 | ) | ||
996 | .unwrap_or(Visibility::Public); | ||
997 | self.def_collector.update( | ||
998 | self.module_id, | ||
999 | &[(Some(mac.name.clone()), PerNs::macros(macro_id, vis))], | ||
1000 | vis, | ||
1001 | ImportType::Named, | ||
1002 | ); | ||
1003 | } | ||
1004 | } | ||
1005 | } | ||
979 | ModItem::Impl(imp) => { | 1006 | ModItem::Impl(imp) => { |
980 | let module = ModuleId { | 1007 | let module = ModuleId { |
981 | krate: self.def_collector.def_map.krate, | 1008 | krate: self.def_collector.def_map.krate, |
@@ -1280,7 +1307,7 @@ impl ModCollector<'_, '_> { | |||
1280 | } | 1307 | } |
1281 | 1308 | ||
1282 | fn collect_macro_rules(&mut self, mac: &MacroRules) { | 1309 | fn collect_macro_rules(&mut self, mac: &MacroRules) { |
1283 | let ast_id = InFile::new(self.file_id, mac.ast_id); | 1310 | let ast_id = InFile::new(self.file_id, mac.ast_id.upcast()); |
1284 | 1311 | ||
1285 | // Case 1: builtin macros | 1312 | // Case 1: builtin macros |
1286 | if mac.is_builtin { | 1313 | if mac.is_builtin { |