@@ -26,7 +26,7 @@ use ra_ap_syntax::{
2626macro_rules! pre_emit {
2727 ( Item , $self: ident, $node: ident) => {
2828 if let Some ( label) = $self. prepare_item_expansion( & $node. clone( ) . into( ) ) {
29- return Some ( label) ;
29+ return Some ( label. into ( ) ) ;
3030 }
3131 } ;
3232 ( $( $_: tt) * ) => { } ;
@@ -694,10 +694,21 @@ impl<'a> Translator<'a> {
694694 }
695695 }
696696
697+ fn is_attribute_macro_target ( & self , node : & ast:: Item ) -> bool {
698+ // rust-analyzer considers as an `attr_macro_call` also a plain macro call, but we want to
699+ // process that differently (in `extract_macro_call_expanded`)
700+ !matches ! ( node, ast:: Item :: MacroCall ( _) )
701+ && self . semantics . is_some_and ( |semantics| {
702+ let file = semantics. hir_file_for ( node. syntax ( ) ) ;
703+ let node = InFile :: new ( file, node) ;
704+ semantics. is_attr_macro_call ( node)
705+ } )
706+ }
707+
697708 pub ( crate ) fn prepare_item_expansion (
698709 & mut self ,
699710 node : & ast:: Item ,
700- ) -> Option < Label < generated:: Item > > {
711+ ) -> Option < Label < generated:: MacroCall > > {
701712 if self . source_kind == SourceKind :: Library {
702713 // if the item expands via an attribute macro, we want to only emit the expansion
703714 if let Some ( expanded) = self . emit_attribute_macro_expansion ( node) {
@@ -714,13 +725,10 @@ impl<'a> Translator<'a> {
714725 expanded. into ( ) ,
715726 & mut self . trap . writer ,
716727 ) ;
717- return Some ( label. into ( ) ) ;
728+ return Some ( label) ;
718729 }
719730 }
720- let semantics = self . semantics . as_ref ( ) ?;
721- let file = semantics. hir_file_for ( node. syntax ( ) ) ;
722- let node = InFile :: new ( file, node) ;
723- if semantics. is_attr_macro_call ( node) {
731+ if self . is_attribute_macro_target ( node) {
724732 self . macro_context_depth += 1 ;
725733 }
726734 None
@@ -730,10 +738,7 @@ impl<'a> Translator<'a> {
730738 & mut self ,
731739 node : & ast:: Item ,
732740 ) -> Option < Label < generated:: MacroItems > > {
733- let semantics = self . semantics ?;
734- let file = semantics. hir_file_for ( node. syntax ( ) ) ;
735- let infile_node = InFile :: new ( file, node) ;
736- if !semantics. is_attr_macro_call ( infile_node) {
741+ if !self . is_attribute_macro_target ( node) {
737742 return None ;
738743 }
739744 self . macro_context_depth -= 1 ;
@@ -743,7 +748,7 @@ impl<'a> Translator<'a> {
743748 }
744749 let ExpandResult {
745750 value : expanded, ..
746- } = semantics. expand_attr_macro ( node) ?;
751+ } = self . semantics . and_then ( |s| s . expand_attr_macro ( node) ) ?;
747752 self . emit_macro_expansion_parse_errors ( node, & expanded) ;
748753 let macro_items = ast:: MacroItems :: cast ( expanded) . or_else ( || {
749754 let message = "attribute macro expansion cannot be cast to MacroItems" . to_owned ( ) ;
0 commit comments