Created expand_allowed_builtins, updated expand_macro to call this function

This commit is contained in:
Ishan Jain 2024-06-15 15:20:46 +05:30
parent 2df806a3a5
commit 020537cd06
No known key found for this signature in database
GPG key ID: 0506DB2A1CC75C27
2 changed files with 20 additions and 3 deletions

View file

@ -315,6 +315,22 @@ impl<'db> SemanticsImpl<'db> {
pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> { pub fn expand(&self, macro_call: &ast::MacroCall) -> Option<SyntaxNode> {
let sa = self.analyze_no_infer(macro_call.syntax())?; 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 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 macro_call = InFile::new(sa.file_id, macro_call);
let file_id = if let Some(call) = let file_id = if let Some(call) =
<ast::MacroCall as crate::semantics::ToDef>::to_def(self, macro_call) <ast::MacroCall as crate::semantics::ToDef>::to_def(self, macro_call)

View file

@ -111,9 +111,10 @@ fn expand_macro_recur(
macro_call: &ast::Item, macro_call: &ast::Item,
) -> Option<SyntaxNode> { ) -> Option<SyntaxNode> {
let expanded = match macro_call { let expanded = match macro_call {
item @ ast::Item::MacroCall(macro_call) => { item @ ast::Item::MacroCall(macro_call) => sema
sema.expand_attr_macro(item).or_else(|| sema.expand(macro_call))?.clone_for_update() .expand_attr_macro(item)
} .or_else(|| sema.expand_allowed_builtins(macro_call))?
.clone_for_update(),
item => sema.expand_attr_macro(item)?.clone_for_update(), item => sema.expand_attr_macro(item)?.clone_for_update(),
}; };
expand(sema, expanded) expand(sema, expanded)