diff options
Diffstat (limited to 'crates/ra_hir/src/nameres/collector.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index f897547e3..10c32ffa1 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs | |||
@@ -14,8 +14,8 @@ use crate::{ | |||
14 | raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, ModuleDef, PerNs, | 14 | raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, ModuleDef, PerNs, |
15 | ReachedFixedPoint, Resolution, ResolveMode, | 15 | ReachedFixedPoint, Resolution, ResolveMode, |
16 | }, | 16 | }, |
17 | AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, Static, Struct, Trait, | 17 | AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, |
18 | TypeAlias, Union, | 18 | Struct, Trait, TypeAlias, Union, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { | 21 | pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -156,9 +156,6 @@ where | |||
156 | /// the definition of current module. | 156 | /// the definition of current module. |
157 | /// And also, `macro_use` on a module will import all textual macros visable inside to | 157 | /// And also, `macro_use` on a module will import all textual macros visable inside to |
158 | /// current textual scope, with possible shadowing. | 158 | /// current textual scope, with possible shadowing. |
159 | /// | ||
160 | /// In a single module, the order of definition/usage of textual scoped macros matters. | ||
161 | /// But we ignore it here to make it easy to implement. | ||
162 | fn define_textual_macro(&mut self, module_id: CrateModuleId, name: Name, macro_id: MacroDefId) { | 159 | fn define_textual_macro(&mut self, module_id: CrateModuleId, name: Name, macro_id: MacroDefId) { |
163 | // Always shadowing | 160 | // Always shadowing |
164 | self.def_map.modules[module_id] | 161 | self.def_map.modules[module_id] |
@@ -700,8 +697,13 @@ where | |||
700 | return; | 697 | return; |
701 | } | 698 | } |
702 | 699 | ||
703 | // Case 3: path to a macro from another crate, expand during name resolution | 700 | // Case 3: resolve in module scope, expand during name resolution. |
704 | self.def_collector.unexpanded_macros.push((self.module_id, ast_id, mac.path.clone())) | 701 | // We rewrite simple path `macro_name` to `self::macro_name` to force resolve in module scope only. |
702 | let mut path = mac.path.clone(); | ||
703 | if path.is_ident() { | ||
704 | path.kind = PathKind::Self_; | ||
705 | } | ||
706 | self.def_collector.unexpanded_macros.push((self.module_id, ast_id, path)); | ||
705 | } | 707 | } |
706 | 708 | ||
707 | fn import_all_textual_macros(&mut self, module_id: CrateModuleId) { | 709 | fn import_all_textual_macros(&mut self, module_id: CrateModuleId) { |