From 7202ce6c963f047b8890ee50acc5aaf5d65f175d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 2 Feb 2021 11:46:58 +0100 Subject: Revert "Use block_def_map in body lowering" --- crates/hir_def/src/body.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'crates/hir_def/src/body.rs') 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 { pub(crate) struct Expander { cfg_expander: CfgExpander, - def_map: Arc, + crate_def_map: Arc, current_file_id: HirFileId, ast_id_map: Arc, module: ModuleId, @@ -91,7 +91,7 @@ impl Expander { let ast_id_map = db.ast_id_map(current_file_id); Expander { cfg_expander, - def_map: crate_def_map, + crate_def_map, current_file_id, ast_id_map, module, @@ -102,6 +102,7 @@ impl Expander { pub(crate) fn enter_expand( &mut self, db: &dyn DefDatabase, + local_scope: Option<&ItemScope>, macro_call: ast::MacroCall, ) -> ExpandResult> { if self.recursion_limit + 1 > EXPANSION_RECURSION_LIMIT { @@ -111,12 +112,18 @@ impl Expander { let macro_call = InFile::new(self.current_file_id, ¯o_call); - let resolver = - |path: ModPath| -> Option { self.resolve_path_as_macro(db, &path) }; + let resolver = |path: ModPath| -> Option { + if let Some(local_scope) = local_scope { + if let Some(def) = path.as_ident().and_then(|n| local_scope.get_legacy_macro(n)) { + return Some(def); + } + } + self.resolve_path_as_macro(db, &path) + }; let mut err = None; let call_id = - macro_call.as_call_id_with_errors(db, self.def_map.krate(), resolver, &mut |e| { + macro_call.as_call_id_with_errors(db, self.crate_def_map.krate(), resolver, &mut |e| { err.get_or_insert(e); }); let call_id = match call_id { @@ -197,7 +204,7 @@ impl Expander { } fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option { - self.def_map + self.crate_def_map .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) .0 .take_macros() -- cgit v1.2.3