@@ -26,7 +26,7 @@ use ra_ap_syntax::{
26
26
macro_rules! pre_emit {
27
27
( Item , $self: ident, $node: ident) => {
28
28
if let Some ( label) = $self. prepare_item_expansion( & $node. clone( ) . into( ) ) {
29
- return Some ( label) ;
29
+ return Some ( label. into ( ) ) ;
30
30
}
31
31
} ;
32
32
( $( $_: tt) * ) => { } ;
@@ -694,10 +694,21 @@ impl<'a> Translator<'a> {
694
694
}
695
695
}
696
696
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
+
697
708
pub ( crate ) fn prepare_item_expansion (
698
709
& mut self ,
699
710
node : & ast:: Item ,
700
- ) -> Option < Label < generated:: Item > > {
711
+ ) -> Option < Label < generated:: MacroCall > > {
701
712
if self . source_kind == SourceKind :: Library {
702
713
// if the item expands via an attribute macro, we want to only emit the expansion
703
714
if let Some ( expanded) = self . emit_attribute_macro_expansion ( node) {
@@ -714,13 +725,10 @@ impl<'a> Translator<'a> {
714
725
expanded. into ( ) ,
715
726
& mut self . trap . writer ,
716
727
) ;
717
- return Some ( label. into ( ) ) ;
728
+ return Some ( label) ;
718
729
}
719
730
}
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) {
724
732
self . macro_context_depth += 1 ;
725
733
}
726
734
None
@@ -730,10 +738,7 @@ impl<'a> Translator<'a> {
730
738
& mut self ,
731
739
node : & ast:: Item ,
732
740
) -> 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) {
737
742
return None ;
738
743
}
739
744
self . macro_context_depth -= 1 ;
@@ -743,7 +748,7 @@ impl<'a> Translator<'a> {
743
748
}
744
749
let ExpandResult {
745
750
value : expanded, ..
746
- } = semantics. expand_attr_macro ( node) ?;
751
+ } = self . semantics . and_then ( |s| s . expand_attr_macro ( node) ) ?;
747
752
self . emit_macro_expansion_parse_errors ( node, & expanded) ;
748
753
let macro_items = ast:: MacroItems :: cast ( expanded) . or_else ( || {
749
754
let message = "attribute macro expansion cannot be cast to MacroItems" . to_owned ( ) ;
0 commit comments