about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2022-01-07 16:20:53 -0800
committerNoah Lev <camelidcamel@gmail.com>2022-02-09 11:39:12 -0800
commit1115f69bf4bc96201a130c876f1a2e866f58c907 (patch)
tree08808ece68e3adc5af9979c58e6a8a1bd035a63e
parentfa400ace11f9db1e299fef3992d3301ccd985bf0 (diff)
downloadrust-1115f69bf4bc96201a130c876f1a2e866f58c907.tar.gz
rust-1115f69bf4bc96201a130c876f1a2e866f58c907.zip
Deduplicate item sections
-rw-r--r--src/librustdoc/html/render/mod.rs15
-rw-r--r--src/librustdoc/html/render/print_item.rs20
2 files changed, 13 insertions, 22 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 3fd94fb9dc5..279047a2d1c 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -2534,19 +2534,11 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
 fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
     let mut sidebar = String::new();
 
-    // Re-exports are handled a bit differently because they can be extern crates or imports.
-    if items.iter().any(|it| {
-        it.name.is_some()
-            && (it.type_() == ItemType::ExternCrate
-                || (it.type_() == ItemType::Import && !it.is_stripped()))
-    }) {
-        let sec = item_ty_to_section(ItemType::Import);
-        sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name()));
-    }
-
+    let mut already_emitted_sections = FxHashSet::default();
     // ordering taken from item_module, reorder, where it prioritized elements in a certain order
     // to print its headings
     for &myty in &[
+        ItemType::Import,
         ItemType::Primitive,
         ItemType::Module,
         ItemType::Macro,
@@ -2570,6 +2562,9 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
     ] {
         if items.iter().any(|it| !it.is_stripped() && it.type_() == myty && it.name.is_some()) {
             let sec = item_ty_to_section(myty);
+            if !already_emitted_sections.insert(sec) {
+                continue;
+            }
             sidebar.push_str(&format!("<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name()));
         }
     }
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index d73bc658f9f..e781e3c1ef4 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -271,7 +271,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
     });
 
     debug!("{:?}", indices);
-    let mut curty = None;
+    let mut last_section = None;
 
     for &idx in &indices {
         let myitem = &items[idx];
@@ -279,24 +279,20 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
             continue;
         }
 
-        let myty = Some(myitem.type_());
-        if curty == Some(ItemType::ExternCrate) && myty == Some(ItemType::Import) {
-            // Put `extern crate` and `use` re-exports in the same section.
-            curty = myty;
-        } else if myty != curty {
-            if curty.is_some() {
+        let my_section = item_ty_to_section(myitem.type_());
+        if Some(my_section) != last_section {
+            if last_section.is_some() {
                 w.write_str(ITEM_TABLE_CLOSE);
             }
-            curty = myty;
-            let sec = item_ty_to_section(myty.unwrap());
+            last_section = Some(my_section);
             write!(
                 w,
                 "<h2 id=\"{id}\" class=\"small-section-header\">\
                     <a href=\"#{id}\">{name}</a>\
                  </h2>\n{}",
                 ITEM_TABLE_OPEN,
-                id = cx.derive_id(sec.id().to_owned()),
-                name = sec.name(),
+                id = cx.derive_id(my_section.id().to_owned()),
+                name = my_section.name(),
             );
         }
 
@@ -408,7 +404,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
         }
     }
 
-    if curty.is_some() {
+    if last_section.is_some() {
         w.write_str(ITEM_TABLE_CLOSE);
     }
 }