@@ -13,6 +13,7 @@ use rustc_middle::ty::TyCtxt;
1313use rustc_session:: Session ;
1414use rustc_span:: edition:: Edition ;
1515use rustc_span:: { FileName , Symbol , sym} ;
16+ use serde:: ser:: SerializeSeq ;
1617use tracing:: info;
1718
1819use super :: print_item:: { full_path, print_item, print_item_path} ;
@@ -163,6 +164,27 @@ impl SharedContext<'_> {
163164 }
164165}
165166
167+ struct SidebarItem {
168+ name : String ,
169+ is_actually_macro : bool ,
170+ }
171+
172+ impl serde:: Serialize for SidebarItem {
173+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
174+ where
175+ S : serde:: Serializer ,
176+ {
177+ if self . is_actually_macro {
178+ let mut seq = serializer. serialize_seq ( Some ( 2 ) ) ?;
179+ seq. serialize_element ( & self . name ) ?;
180+ seq. serialize_element ( & 1 ) ?;
181+ seq. end ( )
182+ } else {
183+ serializer. serialize_some ( & Some ( & self . name ) )
184+ }
185+ }
186+ }
187+
166188impl < ' tcx > Context < ' tcx > {
167189 pub ( crate ) fn tcx ( & self ) -> TyCtxt < ' tcx > {
168190 self . shared . tcx
@@ -290,7 +312,20 @@ impl<'tcx> Context<'tcx> {
290312 }
291313
292314 /// Construct a map of items shown in the sidebar to a plain-text summary of their docs.
293- fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < String > > {
315+ fn build_sidebar_items ( & self , m : & clean:: Module ) -> BTreeMap < String , Vec < SidebarItem > > {
316+ fn build_sidebar_items_inner (
317+ name : Symbol ,
318+ type_ : ItemType ,
319+ map : & mut BTreeMap < String , Vec < SidebarItem > > ,
320+ inserted : & mut FxHashMap < ItemType , FxHashSet < Symbol > > ,
321+ is_actually_macro : bool ,
322+ ) {
323+ if inserted. entry ( type_) . or_default ( ) . insert ( name) {
324+ let type_ = type_. to_string ( ) ;
325+ let name = name. to_string ( ) ;
326+ map. entry ( type_) . or_default ( ) . push ( SidebarItem { name, is_actually_macro } ) ;
327+ }
328+ }
294329 // BTreeMap instead of HashMap to get a sorted output
295330 let mut map: BTreeMap < _ , Vec < _ > > = BTreeMap :: new ( ) ;
296331 let mut inserted: FxHashMap < ItemType , FxHashSet < Symbol > > = FxHashMap :: default ( ) ;
@@ -299,23 +334,24 @@ impl<'tcx> Context<'tcx> {
299334 if item. is_stripped ( ) {
300335 continue ;
301336 }
302-
303- let short = item. type_ ( ) ;
304- let myname = match item. name {
337+ let name = match item. name {
305338 None => continue ,
306339 Some ( s) => s,
307340 } ;
308- if inserted. entry ( short) . or_default ( ) . insert ( myname) {
309- let short = short. to_string ( ) ;
310- let myname = myname. to_string ( ) ;
311- map. entry ( short) . or_default ( ) . push ( myname) ;
341+
342+ if let Some ( types) = item. bang_macro_types ( ) {
343+ for type_ in types {
344+ build_sidebar_items_inner ( name, type_, & mut map, & mut inserted, true ) ;
345+ }
346+ } else {
347+ build_sidebar_items_inner ( name, item. type_ ( ) , & mut map, & mut inserted, false ) ;
312348 }
313349 }
314350
315351 match self . shared . module_sorting {
316352 ModuleSorting :: Alphabetical => {
317353 for items in map. values_mut ( ) {
318- items. sort ( ) ;
354+ items. sort_by ( |a , b| a . name . cmp ( & b . name ) ) ;
319355 }
320356 }
321357 ModuleSorting :: DeclarationOrder => { }
@@ -843,7 +879,11 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
843879 self . shared . fs . write ( joint_dst, buf) ?;
844880
845881 if !self . info . render_redirect_pages {
846- self . shared . all . borrow_mut ( ) . append ( full_path ( self , item) , & item_type) ;
882+ self . shared . all . borrow_mut ( ) . append (
883+ full_path ( self , item) ,
884+ & item_type,
885+ item. bang_macro_types ( ) ,
886+ ) ;
847887 }
848888 // If the item is a macro, redirect from the old macro URL (with !)
849889 // to the new one (without).
0 commit comments