@@ -13,7 +13,9 @@ use crate::{
13
13
intern:: Interned ,
14
14
item_tree:: { self , AssocItem , FnFlags , ItemTree , ItemTreeId , ModItem , Param , TreeId } ,
15
15
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 } ,
17
19
DefMap ,
18
20
} ,
19
21
type_ref:: { TraitRef , TypeBound , TypeRef } ,
@@ -348,6 +350,10 @@ impl ImplData {
348
350
pub struct Macro2Data {
349
351
pub name : Name ,
350
352
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 ] > > ,
351
357
}
352
358
353
359
impl Macro2Data {
@@ -356,9 +362,18 @@ impl Macro2Data {
356
362
let item_tree = loc. id . item_tree ( db) ;
357
363
let makro = & item_tree[ loc. id . value ] ;
358
364
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
+
359
373
Arc :: new ( Macro2Data {
360
374
name : makro. name . clone ( ) ,
361
375
visibility : item_tree[ makro. visibility ] . clone ( ) ,
376
+ helpers,
362
377
} )
363
378
}
364
379
}
0 commit comments