@@ -2402,78 +2402,170 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
24022402 }
24032403}
24042404
2405- fn item_ty_to_strs ( ty : ItemType ) -> ( & ' static str , & ' static str ) {
2405+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
2406+ enum ItemSection {
2407+ Reexports ,
2408+ PrimitiveTypes ,
2409+ Modules ,
2410+ Macros ,
2411+ Structs ,
2412+ Enums ,
2413+ Constants ,
2414+ Statics ,
2415+ Traits ,
2416+ Functions ,
2417+ TypeDefinitions ,
2418+ Unions ,
2419+ Implementations ,
2420+ TypeMethods ,
2421+ Methods ,
2422+ StructFields ,
2423+ Variants ,
2424+ AssociatedTypes ,
2425+ AssociatedConstants ,
2426+ ForeignTypes ,
2427+ Keywords ,
2428+ OpaqueTypes ,
2429+ AttributeMacros ,
2430+ DeriveMacros ,
2431+ TraitAliases ,
2432+ }
2433+
2434+ impl ItemSection {
2435+ const ALL : & ' static [ Self ] = {
2436+ use ItemSection :: * ;
2437+ // NOTE: The order here affects the order in the UI.
2438+ & [
2439+ Reexports ,
2440+ PrimitiveTypes ,
2441+ Modules ,
2442+ Macros ,
2443+ Structs ,
2444+ Enums ,
2445+ Constants ,
2446+ Statics ,
2447+ Traits ,
2448+ Functions ,
2449+ TypeDefinitions ,
2450+ Unions ,
2451+ Implementations ,
2452+ TypeMethods ,
2453+ Methods ,
2454+ StructFields ,
2455+ Variants ,
2456+ AssociatedTypes ,
2457+ AssociatedConstants ,
2458+ ForeignTypes ,
2459+ Keywords ,
2460+ OpaqueTypes ,
2461+ AttributeMacros ,
2462+ DeriveMacros ,
2463+ TraitAliases ,
2464+ ]
2465+ } ;
2466+
2467+ fn id ( self ) -> & ' static str {
2468+ match self {
2469+ Self :: Reexports => "reexports" ,
2470+ Self :: Modules => "modules" ,
2471+ Self :: Structs => "structs" ,
2472+ Self :: Unions => "unions" ,
2473+ Self :: Enums => "enums" ,
2474+ Self :: Functions => "functions" ,
2475+ Self :: TypeDefinitions => "types" ,
2476+ Self :: Statics => "statics" ,
2477+ Self :: Constants => "constants" ,
2478+ Self :: Traits => "traits" ,
2479+ Self :: Implementations => "impls" ,
2480+ Self :: TypeMethods => "tymethods" ,
2481+ Self :: Methods => "methods" ,
2482+ Self :: StructFields => "fields" ,
2483+ Self :: Variants => "variants" ,
2484+ Self :: Macros => "macros" ,
2485+ Self :: PrimitiveTypes => "primitives" ,
2486+ Self :: AssociatedTypes => "associated-types" ,
2487+ Self :: AssociatedConstants => "associated-consts" ,
2488+ Self :: ForeignTypes => "foreign-types" ,
2489+ Self :: Keywords => "keywords" ,
2490+ Self :: OpaqueTypes => "opaque-types" ,
2491+ Self :: AttributeMacros => "attributes" ,
2492+ Self :: DeriveMacros => "derives" ,
2493+ Self :: TraitAliases => "trait-aliases" ,
2494+ }
2495+ }
2496+
2497+ fn name ( self ) -> & ' static str {
2498+ match self {
2499+ Self :: Reexports => "Re-exports" ,
2500+ Self :: Modules => "Modules" ,
2501+ Self :: Structs => "Structs" ,
2502+ Self :: Unions => "Unions" ,
2503+ Self :: Enums => "Enums" ,
2504+ Self :: Functions => "Functions" ,
2505+ Self :: TypeDefinitions => "Type Definitions" ,
2506+ Self :: Statics => "Statics" ,
2507+ Self :: Constants => "Constants" ,
2508+ Self :: Traits => "Traits" ,
2509+ Self :: Implementations => "Implementations" ,
2510+ Self :: TypeMethods => "Type Methods" ,
2511+ Self :: Methods => "Methods" ,
2512+ Self :: StructFields => "Struct Fields" ,
2513+ Self :: Variants => "Variants" ,
2514+ Self :: Macros => "Macros" ,
2515+ Self :: PrimitiveTypes => "Primitive Types" ,
2516+ Self :: AssociatedTypes => "Associated Types" ,
2517+ Self :: AssociatedConstants => "Associated Constants" ,
2518+ Self :: ForeignTypes => "Foreign Types" ,
2519+ Self :: Keywords => "Keywords" ,
2520+ Self :: OpaqueTypes => "Opaque Types" ,
2521+ Self :: AttributeMacros => "Attribute Macros" ,
2522+ Self :: DeriveMacros => "Derive Macros" ,
2523+ Self :: TraitAliases => "Trait Aliases" ,
2524+ }
2525+ }
2526+ }
2527+
2528+ fn item_ty_to_section ( ty : ItemType ) -> ItemSection {
24062529 match ty {
2407- ItemType :: ExternCrate | ItemType :: Import => ( "reexports" , "Re-exports" ) ,
2408- ItemType :: Module => ( "modules" , " Modules" ) ,
2409- ItemType :: Struct => ( "structs" , " Structs" ) ,
2410- ItemType :: Union => ( "unions" , " Unions" ) ,
2411- ItemType :: Enum => ( "enums" , " Enums" ) ,
2412- ItemType :: Function => ( "functions" , " Functions" ) ,
2413- ItemType :: Typedef => ( "types" , "Type Definitions" ) ,
2414- ItemType :: Static => ( "statics" , " Statics" ) ,
2415- ItemType :: Constant => ( "constants" , " Constants" ) ,
2416- ItemType :: Trait => ( "traits" , " Traits" ) ,
2417- ItemType :: Impl => ( "impls" , " Implementations" ) ,
2418- ItemType :: TyMethod => ( "tymethods" , "Type Methods" ) ,
2419- ItemType :: Method => ( "methods" , " Methods" ) ,
2420- ItemType :: StructField => ( "fields" , "Struct Fields" ) ,
2421- ItemType :: Variant => ( "variants" , " Variants" ) ,
2422- ItemType :: Macro => ( "macros" , " Macros" ) ,
2423- ItemType :: Primitive => ( "primitives" , "Primitive Types" ) ,
2424- ItemType :: AssocType => ( "associated-types" , "Associated Types" ) ,
2425- ItemType :: AssocConst => ( "associated-consts" , "Associated Constants" ) ,
2426- ItemType :: ForeignType => ( "foreign-types" , "Foreign Types" ) ,
2427- ItemType :: Keyword => ( "keywords" , " Keywords" ) ,
2428- ItemType :: OpaqueTy => ( "opaque-types" , "Opaque Types" ) ,
2429- ItemType :: ProcAttribute => ( "attributes" , "Attribute Macros" ) ,
2430- ItemType :: ProcDerive => ( "derives" , "Derive Macros" ) ,
2431- ItemType :: TraitAlias => ( "trait-aliases" , "Trait aliases" ) ,
2530+ ItemType :: ExternCrate | ItemType :: Import => ItemSection :: Reexports ,
2531+ ItemType :: Module => ItemSection :: Modules ,
2532+ ItemType :: Struct => ItemSection :: Structs ,
2533+ ItemType :: Union => ItemSection :: Unions ,
2534+ ItemType :: Enum => ItemSection :: Enums ,
2535+ ItemType :: Function => ItemSection :: Functions ,
2536+ ItemType :: Typedef => ItemSection :: TypeDefinitions ,
2537+ ItemType :: Static => ItemSection :: Statics ,
2538+ ItemType :: Constant => ItemSection :: Constants ,
2539+ ItemType :: Trait => ItemSection :: Traits ,
2540+ ItemType :: Impl => ItemSection :: Implementations ,
2541+ ItemType :: TyMethod => ItemSection :: TypeMethods ,
2542+ ItemType :: Method => ItemSection :: Methods ,
2543+ ItemType :: StructField => ItemSection :: StructFields ,
2544+ ItemType :: Variant => ItemSection :: Variants ,
2545+ ItemType :: Macro => ItemSection :: Macros ,
2546+ ItemType :: Primitive => ItemSection :: PrimitiveTypes ,
2547+ ItemType :: AssocType => ItemSection :: AssociatedTypes ,
2548+ ItemType :: AssocConst => ItemSection :: AssociatedConstants ,
2549+ ItemType :: ForeignType => ItemSection :: ForeignTypes ,
2550+ ItemType :: Keyword => ItemSection :: Keywords ,
2551+ ItemType :: OpaqueTy => ItemSection :: OpaqueTypes ,
2552+ ItemType :: ProcAttribute => ItemSection :: AttributeMacros ,
2553+ ItemType :: ProcDerive => ItemSection :: DeriveMacros ,
2554+ ItemType :: TraitAlias => ItemSection :: TraitAliases ,
24322555 ItemType :: Generic => unreachable ! ( ) ,
24332556 }
24342557}
24352558
24362559fn sidebar_module ( buf : & mut Buffer , items : & [ clean:: Item ] ) {
24372560 let mut sidebar = String :: new ( ) ;
24382561
2439- // Re-exports are handled a bit differently because they can be extern crates or imports.
2440- if items. iter ( ) . any ( |it| {
2441- it. name . is_some ( )
2442- && ( it. type_ ( ) == ItemType :: ExternCrate
2443- || ( it. type_ ( ) == ItemType :: Import && !it. is_stripped ( ) ) )
2444- } ) {
2445- let ( id, name) = item_ty_to_strs ( ItemType :: Import ) ;
2446- sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , id, name) ) ;
2447- }
2448-
2449- // ordering taken from item_module, reorder, where it prioritized elements in a certain order
2450- // to print its headings
2451- for & myty in & [
2452- ItemType :: Primitive ,
2453- ItemType :: Module ,
2454- ItemType :: Macro ,
2455- ItemType :: Struct ,
2456- ItemType :: Enum ,
2457- ItemType :: Constant ,
2458- ItemType :: Static ,
2459- ItemType :: Trait ,
2460- ItemType :: Function ,
2461- ItemType :: Typedef ,
2462- ItemType :: Union ,
2463- ItemType :: Impl ,
2464- ItemType :: TyMethod ,
2465- ItemType :: Method ,
2466- ItemType :: StructField ,
2467- ItemType :: Variant ,
2468- ItemType :: AssocType ,
2469- ItemType :: AssocConst ,
2470- ItemType :: ForeignType ,
2471- ItemType :: Keyword ,
2472- ] {
2473- if items. iter ( ) . any ( |it| !it. is_stripped ( ) && it. type_ ( ) == myty && it. name . is_some ( ) ) {
2474- let ( id, name) = item_ty_to_strs ( myty) ;
2475- sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , id, name) ) ;
2476- }
2562+ let item_sections_in_use: FxHashSet < _ > = items
2563+ . iter ( )
2564+ . filter ( |it| !it. is_stripped ( ) && it. name . is_some ( ) )
2565+ . map ( |it| item_ty_to_section ( it. type_ ( ) ) )
2566+ . collect ( ) ;
2567+ for & sec in ItemSection :: ALL . iter ( ) . filter ( |sec| item_sections_in_use. contains ( sec) ) {
2568+ sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , sec. id( ) , sec. name( ) ) ) ;
24772569 }
24782570
24792571 if !sidebar. is_empty ( ) {
0 commit comments