@@ -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
@@ -761,31 +780,51 @@ fn build_macro(
761780 def_id : DefId ,
762781 name : Symbol ,
763782 macro_kinds : MacroKinds ,
764- ) -> clean:: ItemKind {
783+ ) -> ( clean:: ItemKind , Option < Vec < clean :: ItemKind > > ) {
765784 match CStore :: from_tcx ( cx. tcx ) . load_macro_untracked ( def_id, cx. tcx ) {
766785 LoadedMacro :: MacroDef { def, .. } => match macro_kinds {
767- MacroKinds :: BANG => clean:: MacroItem (
768- clean:: Macro {
769- source : utils:: display_macro_source ( cx, name, & def) ,
770- macro_rules : def. macro_rules ,
771- } ,
786+ MacroKinds :: BANG => (
787+ clean:: MacroItem (
788+ clean:: Macro {
789+ source : utils:: display_macro_source ( cx, name, & def) ,
790+ macro_rules : def. macro_rules ,
791+ } ,
792+ None ,
793+ ) ,
794+ None ,
795+ ) ,
796+ MacroKinds :: DERIVE => (
797+ clean:: ProcMacroItem ( clean:: ProcMacro {
798+ kind : MacroKind :: Derive ,
799+ helpers : Vec :: new ( ) ,
800+ } ) ,
772801 None ,
773802 ) ,
774- MacroKinds :: DERIVE => clean:: ProcMacroItem ( clean:: ProcMacro {
775- kind : MacroKind :: Derive ,
776- helpers : Vec :: new ( ) ,
777- } ) ,
778- MacroKinds :: ATTR => clean:: ProcMacroItem ( clean:: ProcMacro {
779- kind : MacroKind :: Attr ,
780- helpers : Vec :: new ( ) ,
781- } ) ,
782- _ if macro_kinds == ( MacroKinds :: BANG | MacroKinds :: ATTR ) => clean:: MacroItem (
783- clean:: Macro {
784- source : utils:: display_macro_source ( cx, name, & def) ,
785- macro_rules : def. macro_rules ,
786- } ,
787- Some ( macro_kinds) ,
803+ MacroKinds :: ATTR => (
804+ clean:: ProcMacroItem ( clean:: ProcMacro {
805+ kind : MacroKind :: Attr ,
806+ helpers : Vec :: new ( ) ,
807+ } ) ,
808+ None ,
788809 ) ,
810+ _ if macro_kinds. contains ( MacroKinds :: BANG ) => {
811+ let kind = clean:: MacroItem (
812+ clean:: Macro {
813+ source : utils:: display_macro_source ( cx, name, & def) ,
814+ macro_rules : def. macro_rules ,
815+ } ,
816+ Some ( macro_kinds) ,
817+ ) ;
818+ let mut ret = vec ! [ ] ;
819+ for kind in macro_kinds. iter ( ) . filter ( |kind| * kind != MacroKinds :: BANG ) {
820+ match kind {
821+ MacroKinds :: ATTR => ret. push ( clean:: AttrMacroItem ) ,
822+ MacroKinds :: DERIVE => ret. push ( clean:: DeriveMacroItem ) ,
823+ _ => panic ! ( "unsupported macro kind {kind:?}" ) ,
824+ }
825+ }
826+ ( kind, Some ( ret) )
827+ }
789828 _ => panic ! ( "unsupported macro kind {macro_kinds:?}" ) ,
790829 } ,
791830 LoadedMacro :: ProcMacro ( ext) => {
@@ -796,7 +835,7 @@ fn build_macro(
796835 MacroKinds :: DERIVE => MacroKind :: Derive ,
797836 _ => unreachable ! ( ) ,
798837 } ;
799- clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } )
838+ ( clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } ) , None )
800839 }
801840 }
802841}
0 commit comments