diff options
Diffstat (limited to 'crates/hir_def/src/body.rs')
-rw-r--r-- | crates/hir_def/src/body.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 41abd8f83..b9ecf22fa 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs | |||
@@ -46,7 +46,7 @@ pub(crate) struct CfgExpander { | |||
46 | 46 | ||
47 | pub(crate) struct Expander { | 47 | pub(crate) struct Expander { |
48 | cfg_expander: CfgExpander, | 48 | cfg_expander: CfgExpander, |
49 | def_map: Arc<DefMap>, | 49 | crate_def_map: Arc<DefMap>, |
50 | current_file_id: HirFileId, | 50 | current_file_id: HirFileId, |
51 | ast_id_map: Arc<AstIdMap>, | 51 | ast_id_map: Arc<AstIdMap>, |
52 | module: ModuleId, | 52 | module: ModuleId, |
@@ -91,7 +91,7 @@ impl Expander { | |||
91 | let ast_id_map = db.ast_id_map(current_file_id); | 91 | let ast_id_map = db.ast_id_map(current_file_id); |
92 | Expander { | 92 | Expander { |
93 | cfg_expander, | 93 | cfg_expander, |
94 | def_map: crate_def_map, | 94 | crate_def_map, |
95 | current_file_id, | 95 | current_file_id, |
96 | ast_id_map, | 96 | ast_id_map, |
97 | module, | 97 | module, |
@@ -102,6 +102,7 @@ impl Expander { | |||
102 | pub(crate) fn enter_expand<T: ast::AstNode>( | 102 | pub(crate) fn enter_expand<T: ast::AstNode>( |
103 | &mut self, | 103 | &mut self, |
104 | db: &dyn DefDatabase, | 104 | db: &dyn DefDatabase, |
105 | local_scope: Option<&ItemScope>, | ||
105 | macro_call: ast::MacroCall, | 106 | macro_call: ast::MacroCall, |
106 | ) -> ExpandResult<Option<(Mark, T)>> { | 107 | ) -> ExpandResult<Option<(Mark, T)>> { |
107 | if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { | 108 | if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { |
@@ -111,12 +112,18 @@ impl Expander { | |||
111 | 112 | ||
112 | let macro_call = InFile::new(self.current_file_id, ¯o_call); | 113 | let macro_call = InFile::new(self.current_file_id, ¯o_call); |
113 | 114 | ||
114 | let resolver = | 115 | let resolver = |path: ModPath| -> Option<MacroDefId> { |
115 | |path: ModPath| -> Option<MacroDefId> { self.resolve_path_as_macro(db, &path) }; | 116 | if let Some(local_scope) = local_scope { |
117 | if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) { | ||
118 | return Some(def); | ||
119 | } | ||
120 | } | ||
121 | self.resolve_path_as_macro(db, &path) | ||
122 | }; | ||
116 | 123 | ||
117 | let mut err = None; | 124 | let mut err = None; |
118 | let call_id = | 125 | let call_id = |
119 | macro_call.as_call_id_with_errors(db, self.def_map.krate(), resolver, &mut |e| { | 126 | macro_call.as_call_id_with_errors(db, self.crate_def_map.krate(), resolver, &mut |e| { |
120 | err.get_or_insert(e); | 127 | err.get_or_insert(e); |
121 | }); | 128 | }); |
122 | let call_id = match call_id { | 129 | let call_id = match call_id { |
@@ -197,7 +204,7 @@ impl Expander { | |||
197 | } | 204 | } |
198 | 205 | ||
199 | fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { | 206 | fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { |
200 | self.def_map | 207 | self.crate_def_map |
201 | .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) | 208 | .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) |
202 | .0 | 209 | .0 |
203 | .take_macros() | 210 | .take_macros() |