@@ -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} ;
@@ -166,6 +167,27 @@ impl SharedContext<'_> {
166167 }
167168}
168169
170+ struct SidebarItem {
171+ name : String ,
172+ is_actually_macro : bool ,
173+ }
174+
175+ impl serde:: Serialize for SidebarItem {
176+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
177+ where
178+ S : serde:: Serializer ,
179+ {
180+ if self . is_actually_macro {
181+ let mut seq = serializer. serialize_seq ( Some ( 2 ) ) ?;
182+ seq. serialize_element ( & self . name ) ?;
183+ seq. serialize_element ( & 1 ) ?;
184+ seq. end ( )
185+ } else {
186+ serializer. serialize_some ( & Some ( & self . name ) )
187+ }
188+ }
189+ }
190+
169191impl < ' tcx > Context < ' tcx > {
170192 pub ( crate ) fn tcx ( & self ) -> TyCtxt < ' tcx > {
171193 self . shared . tcx
@@ -306,7 +328,20 @@ impl<'tcx> Context<'tcx> {
306328 }
307329
308330 /// Construct a map of items shown in the sidebar to a plain-text summary of their docs.
309- fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < String > > {
331+ fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < SidebarItem > > {
332+ fn build_sidebar_items_inner (
333+ name : Symbol ,
334+ type_ : ItemType ,
335+ map : & mut BTreeMap < String , Vec < SidebarItem > > ,
336+ inserted : & mut FxHashMap < ItemType , FxHashSet < Symbol > > ,
337+ is_actually_macro : bool ,
338+ ) {
339+ if inserted. entry ( type_) . or_default ( ) . insert ( name) {
340+ let type_ = type_. to_string ( ) ;
341+ let name = name. to_string ( ) ;
342+ map. entry ( type_) . or_default ( ) . push ( SidebarItem { name, is_actually_macro } ) ;
343+ }
344+ }
310345 // BTreeMap instead of HashMap to get a sorted output
311346 let mut map: BTreeMap < _ , Vec < _ > > = BTreeMap :: new ( ) ;
312347 let mut inserted: FxHashMap < ItemType , FxHashSet < Symbol > > = FxHashMap :: default ( ) ;
@@ -315,23 +350,24 @@ impl<'tcx> Context<'tcx> {
315350 if item. is_stripped ( ) {
316351 continue ;
317352 }
318-
319- let short = item. type_ ( ) ;
320- let myname = match item. name {
353+ let name = match item. name {
321354 None => continue ,
322355 Some ( s) => s,
323356 } ;
324- if inserted. entry ( short) . or_default ( ) . insert ( myname) {
325- let short = short. to_string ( ) ;
326- let myname = myname. to_string ( ) ;
327- map. entry ( short) . or_default ( ) . push ( myname) ;
357+
358+ if let Some ( types) = item. bang_macro_types ( ) {
359+ for type_ in types {
360+ build_sidebar_items_inner ( name, type_, & mut map, & mut inserted, true ) ;
361+ }
362+ } else {
363+ build_sidebar_items_inner ( name, item. type_ ( ) , & mut map, & mut inserted, false ) ;
328364 }
329365 }
330366
331367 match self . shared . module_sorting {
332368 ModuleSorting :: Alphabetical => {
333369 for items in map. values_mut ( ) {
334- items. sort ( ) ;
370+ items. sort_by ( |a , b| a . name . cmp ( & b . name ) ) ;
335371 }
336372 }
337373 ModuleSorting :: DeclarationOrder => { }
@@ -864,7 +900,11 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
864900 self . shared . fs . write ( joint_dst, buf) ?;
865901
866902 if !self . info . render_redirect_pages {
867- self . shared . all . borrow_mut ( ) . append ( full_path ( self , item) , & item_type) ;
903+ self . shared . all . borrow_mut ( ) . append (
904+ full_path ( self , item) ,
905+ & item_type,
906+ item. bang_macro_types ( ) ,
907+ ) ;
868908 }
869909 // If the item is a macro, redirect from the old macro URL (with !)
870910 // to the new one (without).
0 commit comments