1
Fork 0

Deduplicate item sections

This commit is contained in:
Noah Lev 2022-01-07 16:20:53 -08:00
parent fa400ace11
commit 1115f69bf4
2 changed files with 13 additions and 22 deletions

View file

@ -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()));
}
}