@@ -46,6 +46,27 @@ pub(crate) fn try_inline(
4646 attrs : Option < ( & [ hir:: Attribute ] , Option < LocalDefId > ) > ,
4747 visited : & mut DefIdSet ,
4848) -> Option < Vec < clean:: Item > > {
49+ fn try_inline_inner (
50+ cx : & mut DocContext < ' _ > ,
51+ kind : clean:: ItemKind ,
52+ did : DefId ,
53+ name : Symbol ,
54+ import_def_id : Option < LocalDefId > ,
55+ ) -> clean:: Item {
56+ cx. inlined . insert ( did. into ( ) ) ;
57+ let mut item = crate :: clean:: generate_item_with_correct_attrs (
58+ cx,
59+ kind,
60+ did,
61+ name,
62+ import_def_id. as_slice ( ) ,
63+ None ,
64+ ) ;
65+ // The visibility needs to reflect the one from the reexport and not from the "source" DefId.
66+ item. inner . inline_stmt_id = import_def_id;
67+ item
68+ }
69+
4970 let did = res. opt_def_id ( ) ?;
5071 if did. is_local ( ) {
5172 return None ;
@@ -138,7 +159,7 @@ pub(crate) fn try_inline(
138159 } )
139160 }
140161 Res :: Def ( DefKind :: Macro ( kinds) , did) => {
141- let mac = build_macro ( cx, did, name, kinds) ;
162+ let ( mac, others ) = build_macro ( cx, did, name, kinds) ;
142163
143164 let type_kind = match kinds {
144165 MacroKinds :: BANG => ItemType :: Macro ,
@@ -148,23 +169,21 @@ pub(crate) fn try_inline(
148169 _ => panic ! ( "unsupported macro kind {kinds:?}" ) ,
149170 } ;
150171 record_extern_fqn ( cx, did, type_kind) ;
151- mac
172+ let first = try_inline_inner ( cx, mac, did, name, import_def_id) ;
173+ if let Some ( others) = others {
174+ for mac_kind in others {
175+ let mut mac = first. clone ( ) ;
176+ mac. inner . kind = mac_kind;
177+ ret. push ( mac) ;
178+ }
179+ }
180+ ret. push ( first) ;
181+ return Some ( ret) ;
152182 }
153183 _ => return None ,
154184 } ;
155185
156- cx. inlined . insert ( did. into ( ) ) ;
157- let mut item = crate :: clean:: generate_item_with_correct_attrs (
158- cx,
159- kind,
160- did,
161- name,
162- import_def_id. as_slice ( ) ,
163- None ,
164- ) ;
165- // The visibility needs to reflect the one from the reexport and not from the "source" DefId.
166- item. inner . inline_stmt_id = import_def_id;
167- ret. push ( item) ;
186+ ret. push ( try_inline_inner ( cx, kind, did, name, import_def_id) ) ;
168187 Some ( ret)
169188}
170189
@@ -752,31 +771,51 @@ fn build_macro(
752771 def_id : DefId ,
753772 name : Symbol ,
754773 macro_kinds : MacroKinds ,
755- ) -> clean:: ItemKind {
774+ ) -> ( clean:: ItemKind , Option < Vec < clean :: ItemKind > > ) {
756775 match CStore :: from_tcx ( cx. tcx ) . load_macro_untracked ( def_id, cx. tcx ) {
757776 LoadedMacro :: MacroDef { def, .. } => match macro_kinds {
758- MacroKinds :: BANG => clean:: MacroItem (
759- clean:: Macro {
760- source : utils:: display_macro_source ( cx, name, & def) ,
761- macro_rules : def. macro_rules ,
762- } ,
777+ MacroKinds :: BANG => (
778+ clean:: MacroItem (
779+ clean:: Macro {
780+ source : utils:: display_macro_source ( cx, name, & def) ,
781+ macro_rules : def. macro_rules ,
782+ } ,
783+ None ,
784+ ) ,
785+ None ,
786+ ) ,
787+ MacroKinds :: DERIVE => (
788+ clean:: ProcMacroItem ( clean:: ProcMacro {
789+ kind : MacroKind :: Derive ,
790+ helpers : Vec :: new ( ) ,
791+ } ) ,
763792 None ,
764793 ) ,
765- MacroKinds :: DERIVE => clean:: ProcMacroItem ( clean:: ProcMacro {
766- kind : MacroKind :: Derive ,
767- helpers : Vec :: new ( ) ,
768- } ) ,
769- MacroKinds :: ATTR => clean:: ProcMacroItem ( clean:: ProcMacro {
770- kind : MacroKind :: Attr ,
771- helpers : Vec :: new ( ) ,
772- } ) ,
773- _ if macro_kinds == ( MacroKinds :: BANG | MacroKinds :: ATTR ) => clean:: MacroItem (
774- clean:: Macro {
775- source : utils:: display_macro_source ( cx, name, & def) ,
776- macro_rules : def. macro_rules ,
777- } ,
778- Some ( macro_kinds) ,
794+ MacroKinds :: ATTR => (
795+ clean:: ProcMacroItem ( clean:: ProcMacro {
796+ kind : MacroKind :: Attr ,
797+ helpers : Vec :: new ( ) ,
798+ } ) ,
799+ None ,
779800 ) ,
801+ _ if macro_kinds. contains ( MacroKinds :: BANG ) => {
802+ let kind = clean:: MacroItem (
803+ clean:: Macro {
804+ source : utils:: display_macro_source ( cx, name, & def) ,
805+ macro_rules : def. macro_rules ,
806+ } ,
807+ Some ( macro_kinds) ,
808+ ) ;
809+ let mut ret = vec ! [ ] ;
810+ for kind in macro_kinds. iter ( ) . filter ( |kind| * kind != MacroKinds :: BANG ) {
811+ match kind {
812+ MacroKinds :: ATTR => ret. push ( clean:: AttrMacroItem ) ,
813+ MacroKinds :: DERIVE => ret. push ( clean:: DeriveMacroItem ) ,
814+ _ => panic ! ( "unsupported macro kind {kind:?}" ) ,
815+ }
816+ }
817+ ( kind, Some ( ret) )
818+ }
780819 _ => panic ! ( "unsupported macro kind {macro_kinds:?}" ) ,
781820 } ,
782821 LoadedMacro :: ProcMacro ( ext) => {
@@ -787,7 +826,7 @@ fn build_macro(
787826 MacroKinds :: DERIVE => MacroKind :: Derive ,
788827 _ => unreachable ! ( ) ,
789828 } ;
790- clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } )
829+ ( clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } ) , None )
791830 }
792831 }
793832}
0 commit comments