@@ -46,6 +46,27 @@ pub(crate) fn try_inline(
46
46
attrs : Option < ( & [ hir:: Attribute ] , Option < LocalDefId > ) > ,
47
47
visited : & mut DefIdSet ,
48
48
) -> 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
+
49
70
let did = res. opt_def_id ( ) ?;
50
71
if did. is_local ( ) {
51
72
return None ;
@@ -138,7 +159,7 @@ pub(crate) fn try_inline(
138
159
} )
139
160
}
140
161
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) ;
142
163
143
164
let type_kind = match kinds {
144
165
MacroKinds :: BANG => ItemType :: Macro ,
@@ -148,23 +169,21 @@ pub(crate) fn try_inline(
148
169
_ => panic ! ( "unsupported macro kind {kinds:?}" ) ,
149
170
} ;
150
171
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) ;
152
182
}
153
183
_ => return None ,
154
184
} ;
155
185
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) ) ;
168
187
Some ( ret)
169
188
}
170
189
@@ -752,31 +771,51 @@ fn build_macro(
752
771
def_id : DefId ,
753
772
name : Symbol ,
754
773
macro_kinds : MacroKinds ,
755
- ) -> clean:: ItemKind {
774
+ ) -> ( clean:: ItemKind , Option < Vec < clean :: ItemKind > > ) {
756
775
match CStore :: from_tcx ( cx. tcx ) . load_macro_untracked ( def_id, cx. tcx ) {
757
776
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
+ } ) ,
763
792
None ,
764
793
) ,
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 ,
779
800
) ,
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
+ }
780
819
_ => panic ! ( "unsupported macro kind {macro_kinds:?}" ) ,
781
820
} ,
782
821
LoadedMacro :: ProcMacro ( ext) => {
@@ -787,7 +826,7 @@ fn build_macro(
787
826
MacroKinds :: DERIVE => MacroKind :: Derive ,
788
827
_ => unreachable ! ( ) ,
789
828
} ;
790
- clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } )
829
+ ( clean:: ProcMacroItem ( clean:: ProcMacro { kind, helpers : ext. helper_attrs } ) , None )
791
830
}
792
831
}
793
832
}
0 commit comments