@@ -13,6 +13,7 @@ use rustc_middle::ty::TyCtxt;
1313use rustc_session:: Session ;
1414use rustc_span:: edition:: Edition ;
1515use rustc_span:: { BytePos , FileName , Symbol , sym} ;
16+ use serde:: ser:: SerializeSeq ;
1617use tracing:: info;
1718
1819use super :: print_item:: { full_path, print_item, print_item_path} ;
@@ -165,6 +166,27 @@ impl SharedContext<'_> {
165166 }
166167}
167168
169+ struct SidebarItem {
170+ name : String ,
171+ is_actually_macro : bool ,
172+ }
173+
174+ impl serde:: Serialize for SidebarItem {
175+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
176+ where
177+ S : serde:: Serializer ,
178+ {
179+ if self . is_actually_macro {
180+ let mut seq = serializer. serialize_seq ( Some ( 2 ) ) ?;
181+ seq. serialize_element ( & self . name ) ?;
182+ seq. serialize_element ( & 1 ) ?;
183+ seq. end ( )
184+ } else {
185+ serializer. serialize_some ( & Some ( & self . name ) )
186+ }
187+ }
188+ }
189+
168190impl < ' tcx > Context < ' tcx > {
169191 pub ( crate ) fn tcx ( & self ) -> TyCtxt < ' tcx > {
170192 self . shared . tcx
@@ -305,7 +327,20 @@ impl<'tcx> Context<'tcx> {
305327 }
306328
307329 /// Construct a map of items shown in the sidebar to a plain-text summary of their docs.
308- fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < String > > {
330+ fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < SidebarItem > > {
331+ fn build_sidebar_items_inner (
332+ name : Symbol ,
333+ type_ : ItemType ,
334+ map : & mut BTreeMap < String , Vec < SidebarItem > > ,
335+ inserted : & mut FxHashMap < ItemType , FxHashSet < Symbol > > ,
336+ is_actually_macro : bool ,
337+ ) {
338+ if inserted. entry ( type_) . or_default ( ) . insert ( name) {
339+ let type_ = type_. to_string ( ) ;
340+ let name = name. to_string ( ) ;
341+ map. entry ( type_) . or_default ( ) . push ( SidebarItem { name, is_actually_macro } ) ;
342+ }
343+ }
309344 // BTreeMap instead of HashMap to get a sorted output
310345 let mut map: BTreeMap < _ , Vec < _ > > = BTreeMap :: new ( ) ;
311346 let mut inserted: FxHashMap < ItemType , FxHashSet < Symbol > > = FxHashMap :: default ( ) ;
@@ -314,23 +349,24 @@ impl<'tcx> Context<'tcx> {
314349 if item. is_stripped ( ) {
315350 continue ;
316351 }
317-
318- let short = item. type_ ( ) ;
319- let myname = match item. name {
352+ let name = match item. name {
320353 None => continue ,
321354 Some ( s) => s,
322355 } ;
323- if inserted. entry ( short) . or_default ( ) . insert ( myname) {
324- let short = short. to_string ( ) ;
325- let myname = myname. to_string ( ) ;
326- map. entry ( short) . or_default ( ) . push ( myname) ;
356+
357+ if let Some ( types) = item. bang_macro_types ( ) {
358+ for type_ in types {
359+ build_sidebar_items_inner ( name, type_, & mut map, & mut inserted, true ) ;
360+ }
361+ } else {
362+ build_sidebar_items_inner ( name, item. type_ ( ) , & mut map, & mut inserted, false ) ;
327363 }
328364 }
329365
330366 match self . shared . module_sorting {
331367 ModuleSorting :: Alphabetical => {
332368 for items in map. values_mut ( ) {
333- items. sort ( ) ;
369+ items. sort_by ( |a , b| a . name . cmp ( & b . name ) ) ;
334370 }
335371 }
336372 ModuleSorting :: DeclarationOrder => { }
@@ -863,7 +899,11 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
863899 self . shared . fs . write ( joint_dst, buf) ?;
864900
865901 if !self . info . render_redirect_pages {
866- self . shared . all . borrow_mut ( ) . append ( full_path ( self , item) , & item_type) ;
902+ self . shared . all . borrow_mut ( ) . append (
903+ full_path ( self , item) ,
904+ & item_type,
905+ item. bang_macro_types ( ) ,
906+ ) ;
867907 }
868908 // If the item is a macro, redirect from the old macro URL (with !)
869909 // to the new one (without).
0 commit comments