@@ -13,7 +13,9 @@ use crate::{
1313 intern:: Interned ,
1414 item_tree:: { self , AssocItem , FnFlags , ItemTree , ItemTreeId , ModItem , Param , TreeId } ,
1515 nameres:: {
16- attr_resolution:: ResolvedAttr , diagnostics:: DefDiagnostic , proc_macro:: ProcMacroKind ,
16+ attr_resolution:: ResolvedAttr ,
17+ diagnostics:: DefDiagnostic ,
18+ proc_macro:: { parse_macro_name_and_helper_attrs, ProcMacroKind } ,
1719 DefMap ,
1820 } ,
1921 type_ref:: { TraitRef , TypeBound , TypeRef } ,
@@ -348,6 +350,10 @@ impl ImplData {
348350pub struct Macro2Data {
349351 pub name : Name ,
350352 pub visibility : RawVisibility ,
353+ // It's a bit wasteful as currently this is only for builtin `Default` derive macro, but macro2
354+ // are rarely used in practice so I think it's okay for now.
355+ /// Derive helpers, if this is a derive rustc_builtin_macro
356+ pub helpers : Option < Box < [ Name ] > > ,
351357}
352358
353359impl Macro2Data {
@@ -356,9 +362,18 @@ impl Macro2Data {
356362 let item_tree = loc. id . item_tree ( db) ;
357363 let makro = & item_tree[ loc. id . value ] ;
358364
365+ let helpers = item_tree
366+ . attrs ( db, loc. container . krate ( ) , ModItem :: from ( loc. id . value ) . into ( ) )
367+ . by_key ( "rustc_builtin_macro" )
368+ . tt_values ( )
369+ . next ( )
370+ . and_then ( |attr| parse_macro_name_and_helper_attrs ( & attr. token_trees ) )
371+ . map ( |( _, helpers) | helpers) ;
372+
359373 Arc :: new ( Macro2Data {
360374 name : makro. name . clone ( ) ,
361375 visibility : item_tree[ makro. visibility ] . clone ( ) ,
376+ helpers,
362377 } )
363378 }
364379}
0 commit comments