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