about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIshan Jain <contact@ishanjain.me>2024-06-15 15:20:46 +0530
committerIshan Jain <contact@ishanjain.me>2024-06-15 15:20:46 +0530
commit9b619035b9d1e13dc24679a5424af484a598131a (patch)
tree637b99c6c0e58722e814ee794fb26af9edca6ccf
parent1623f151669ad3894e8f6c7e700d821f17ddc16e (diff)
downloadrust-9b619035b9d1e13dc24679a5424af484a598131a.tar.gz
rust-9b619035b9d1e13dc24679a5424af484a598131a.zip
Created expand_allowed_builtins, updated expand_macro to call this function
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/semantics.rs16
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/expand_macro.rs7
2 files changed, 20 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs
index d11731ff2a5..8261828e026 100644
--- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs
@@ -323,6 +323,22 @@ impl<'db> SemanticsImpl<'db> {
         } 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<SyntaxNode> {
+        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) =
+            <ast::MacroCall as crate::semantics::ToDef>::to_def(self, macro_call)
+        {
+            call.as_macro_file()
+        } else {
+            sa.expand(self.db, macro_call)?
+        };
         let macro_call = self.db.lookup_intern_macro_call(file_id.macro_call_id);
 
         match macro_call.def.kind {
diff --git a/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs b/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs
index c411248c482..55838799f6e 100644
--- a/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/expand_macro.rs
@@ -111,9 +111,10 @@ fn expand_macro_recur(
     macro_call: &ast::Item,
 ) -> Option<SyntaxNode> {
     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)