diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index d11731ff2a..8261828e02 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -315,6 +315,22 @@ impl<'db> SemanticsImpl<'db> { pub fn expand(&self, macro_call: &ast::MacroCall) -> Option { let sa = self.analyze_no_infer(macro_call.syntax())?; + let macro_call = InFile::new(sa.file_id, macro_call); + let file_id = if let Some(call) = + ::to_def(self, macro_call) + { + call.as_macro_file() + } else { + sa.expand(self.db, macro_call)? + }; + + let node = self.parse_or_expand(file_id.into()); + Some(node) + } + + pub fn expand_allowed_builtins(&self, macro_call: &ast::MacroCall) -> Option { + let sa = self.analyze_no_infer(macro_call.syntax())?; + let macro_call = InFile::new(sa.file_id, macro_call); let file_id = if let Some(call) = ::to_def(self, macro_call) diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index c411248c48..55838799f6 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -111,9 +111,10 @@ fn expand_macro_recur( macro_call: &ast::Item, ) -> Option { let expanded = match macro_call { - item @ ast::Item::MacroCall(macro_call) => { - sema.expand_attr_macro(item).or_else(|| sema.expand(macro_call))?.clone_for_update() - } + item @ ast::Item::MacroCall(macro_call) => sema + .expand_attr_macro(item) + .or_else(|| sema.expand_allowed_builtins(macro_call))? + .clone_for_update(), item => sema.expand_attr_macro(item)?.clone_for_update(), }; expand(sema, expanded)