@@ -2412,22 +2412,22 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
2412
2412
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2413
2413
enum ItemSection {
2414
2414
Reexports,
2415
+ PrimitiveTypes,
2415
2416
Modules,
2417
+ Macros,
2416
2418
Structs,
2417
- Unions,
2418
2419
Enums,
2419
- Functions,
2420
- TypeDefinitions,
2421
- Statics,
2422
2420
Constants,
2421
+ Statics,
2423
2422
Traits,
2423
+ Functions,
2424
+ TypeDefinitions,
2425
+ Unions,
2424
2426
Implementations,
2425
2427
TypeMethods,
2426
2428
Methods,
2427
2429
StructFields,
2428
2430
Variants,
2429
- Macros,
2430
- PrimitiveTypes,
2431
2431
AssociatedTypes,
2432
2432
AssociatedConstants,
2433
2433
ForeignTypes,
@@ -2439,6 +2439,38 @@ enum ItemSection {
2439
2439
}
2440
2440
2441
2441
impl ItemSection {
2442
+ const ALL: &'static [Self] = {
2443
+ use ItemSection::*;
2444
+ // NOTE: The order here affects the order in the UI.
2445
+ &[
2446
+ Reexports,
2447
+ PrimitiveTypes,
2448
+ Modules,
2449
+ Macros,
2450
+ Structs,
2451
+ Enums,
2452
+ Constants,
2453
+ Statics,
2454
+ Traits,
2455
+ Functions,
2456
+ TypeDefinitions,
2457
+ Unions,
2458
+ Implementations,
2459
+ TypeMethods,
2460
+ Methods,
2461
+ StructFields,
2462
+ Variants,
2463
+ AssociatedTypes,
2464
+ AssociatedConstants,
2465
+ ForeignTypes,
2466
+ Keywords,
2467
+ OpaqueTypes,
2468
+ AttributeMacros,
2469
+ DeriveMacros,
2470
+ TraitAliases,
2471
+ ]
2472
+ };
2473
+
2442
2474
fn id(self) -> &'static str {
2443
2475
match self {
2444
2476
Self::Reexports => "reexports",
@@ -2534,39 +2566,13 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
2534
2566
fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
2535
2567
let mut sidebar = String::new();
2536
2568
2537
- let mut already_emitted_sections = FxHashSet::default();
2538
- // ordering taken from item_module, reorder, where it prioritized elements in a certain order
2539
- // to print its headings
2540
- for &myty in &[
2541
- ItemType::Import,
2542
- ItemType::Primitive,
2543
- ItemType::Module,
2544
- ItemType::Macro,
2545
- ItemType::Struct,
2546
- ItemType::Enum,
2547
- ItemType::Constant,
2548
- ItemType::Static,
2549
- ItemType::Trait,
2550
- ItemType::Function,
2551
- ItemType::Typedef,
2552
- ItemType::Union,
2553
- ItemType::Impl,
2554
- ItemType::TyMethod,
2555
- ItemType::Method,
2556
- ItemType::StructField,
2557
- ItemType::Variant,
2558
- ItemType::AssocType,
2559
- ItemType::AssocConst,
2560
- ItemType::ForeignType,
2561
- ItemType::Keyword,
2562
- ] {
2563
- if items.iter().any(|it| !it.is_stripped() && it.type_() == myty && it.name.is_some()) {
2564
- let sec = item_ty_to_section(myty);
2565
- if !already_emitted_sections.insert(sec) {
2566
- continue;
2567
- }
2568
- sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name()));
2569
- }
2569
+ let item_sections_in_use: FxHashSet<_> = items
2570
+ .iter()
2571
+ .filter(|it| !it.is_stripped() && it.name.is_some())
2572
+ .map(|it| item_ty_to_section(it.type_()))
2573
+ .collect();
2574
+ for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) {
2575
+ sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name()));
2570
2576
}
2571
2577
2572
2578
if !sidebar.is_empty() {
0 commit comments