@@ -7,6 +7,7 @@ use mbe::{syntax_node_to_token_tree, ValueResult};
77use rustc_hash:: FxHashSet ;
88use span:: { AstIdMap , SyntaxContextData , SyntaxContextId } ;
99use syntax:: { ast, AstNode , Parse , SyntaxElement , SyntaxError , SyntaxNode , SyntaxToken , T } ;
10+ use tracing:: debug;
1011use triomphe:: Arc ;
1112
1213use crate :: {
@@ -345,7 +346,13 @@ fn smart_macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
345346 // FIXME: We called lookup_intern_macro_call twice.
346347 match loc. kind {
347348 // Get the macro arg for the derive macro
348- MacroCallKind :: Derive { derive_macro_id, .. } => db. macro_arg ( derive_macro_id) ,
349+ MacroCallKind :: Derive { derive_macro_id, .. } => {
350+ debug ! (
351+ ?loc,
352+ "{id:?} is a derive macro. Using the derive macro, id: {derive_macro_id:?}, attribute as the macro arg."
353+ ) ;
354+ db. macro_arg ( derive_macro_id)
355+ }
349356 // Normal macro arg
350357 _ => db. macro_arg ( id) ,
351358 }
@@ -455,7 +462,12 @@ fn macro_arg(
455462 }
456463 MacroCallKind :: Attr { ast_id, invoc_attr_index, .. } => {
457464 let node = ast_id. to_ptr ( db) . to_node ( & root) ;
458- ( censor_attr_input ( invoc_attr_index, & node) , node)
465+ if loc. def . is_attribute_derive ( ) && ast:: Adt :: can_cast ( node. syntax ( ) . kind ( ) ) {
466+ let node = ast:: Adt :: cast ( node. syntax ( ) . clone ( ) ) . unwrap ( ) ;
467+ ( censor_derive_input ( invoc_attr_index, & node) , node. into ( ) )
468+ } else {
469+ ( censor_attr_input ( invoc_attr_index, & node) , node)
470+ }
459471 }
460472 } ;
461473
0 commit comments