]> git.lizzy.rs Git - rust.git/commitdiff
collect macro_rules! macros into macro declarations
authorJake Heinz <jh@discordapp.com>
Mon, 29 Nov 2021 05:28:22 +0000 (05:28 +0000)
committerJake Heinz <jh@discordapp.com>
Mon, 29 Nov 2021 05:28:22 +0000 (05:28 +0000)
crates/hir_def/src/item_scope.rs
crates/hir_def/src/nameres/collector.rs
crates/ide_db/src/symbol_index.rs

index 8b5984bf1233d2ac8570beab4cb5d936ae6fa419..37599371f61fee8f13a6ddae18172740f0061e39 100644 (file)
@@ -127,7 +127,7 @@ pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId
     }
 
     /// Iterate over all legacy textual scoped macros visible at the end of the module
-    pub fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
+    pub(crate) fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
         self.legacy_macros.iter().map(|(name, def)| (name, *def))
     }
 
index 49d2a7866a3683b6713c86b35cf00ff9f4089b00..d7a35caf29eef4c774c73f6cff2be6ff737c3fe0 100644 (file)
@@ -594,6 +594,7 @@ fn define_macro_rules(
     ) {
         // Textual scoping
         self.define_legacy_macro(module_id, name.clone(), macro_);
+        self.def_map.modules[module_id].scope.declare_macro(macro_);
 
         // Module scoping
         // In Rust, `#[macro_export]` macros are unconditionally visible at the
index 53fa3f0881ffba8895a00bd71a7463d23214c046..b8efa279e1bae693c4f0b5c0cc337e1d1f0629c3 100644 (file)
@@ -490,8 +490,6 @@ fn collect_from_module(&mut self, module_id: ModuleId) {
         let module_data = &def_map[module_id.local_id];
         let scope = &module_data.scope;
 
-        dbg!(scope);
-
         for module_def_id in scope.declarations() {
             match module_def_id {
                 ModuleDefId::ModuleId(id) => self.push_module(id),
@@ -533,13 +531,6 @@ fn collect_from_module(&mut self, module_id: ModuleId) {
             self.work.push(SymbolCollectorWorkItem::Body { body: const_id.into() })
         }
 
-        // Collect legacy macros from the root module only:
-        if module_data.parent.is_none() {
-            for (_, macro_def_id) in scope.legacy_macros() {
-                self.push_decl_macro(macro_def_id.into());
-            }
-        }
-
         for macro_def_id in scope.macro_declarations() {
             self.push_decl_macro(macro_def_id.into());
         }
@@ -699,7 +690,7 @@ fn push_module(&mut self, module_id: ModuleId) {
         })
     }
 
-    pub(crate) fn push_decl_macro(&mut self, macro_def: MacroDef) {
+    fn push_decl_macro(&mut self, macro_def: MacroDef) {
         self.push_file_symbol(|s| {
             let name = macro_def.name(s.db.upcast())?.as_text()?;
             let source = macro_def.source(s.db.upcast())?;