diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index cd49da88d96..5b364ed95cf 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -4067,9 +4067,9 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
.filter(|i| i.inner_impl().trait_.is_none())
.flat_map(move |i| get_methods(i.inner_impl(), false, used_links_bor, false))
.collect::>();
- // We want links' order to be reproducible so we don't use unstable sort.
- ret.sort();
if !ret.is_empty() {
+ // We want links' order to be reproducible so we don't use unstable sort.
+ ret.sort();
out.push_str(&format!(
"\
",
@@ -4240,7 +4240,7 @@ fn is_negative_impl(i: &clean::Impl) -> bool {
fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
let mut sidebar = String::new();
- let types = t
+ let mut types = t
.items
.iter()
.filter_map(|m| match m.name {
@@ -4249,8 +4249,8 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
}
_ => None,
})
- .collect::();
- let consts = t
+ .collect::>();
+ let mut consts = t
.items
.iter()
.filter_map(|m| match m.name {
@@ -4259,7 +4259,7 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
}
_ => None,
})
- .collect::();
+ .collect::>();
let mut required = t
.items
.iter()
@@ -4282,24 +4282,26 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
.collect::>();
if !types.is_empty() {
+ types.sort();
sidebar.push_str(&format!(
"",
- types
+ Associated Types",
+ types.join("")
));
}
if !consts.is_empty() {
+ consts.sort();
sidebar.push_str(&format!(
"",
- consts
+ Associated Constants",
+ consts.join("")
));
}
if !required.is_empty() {
required.sort();
sidebar.push_str(&format!(
"",
+ Required Methods",
required.join("")
));
}
@@ -4307,7 +4309,7 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
provided.sort();
sidebar.push_str(&format!(
"",
+ Provided Methods",
provided.join("")
));
}
@@ -4325,8 +4327,8 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
res.sort();
sidebar.push_str(&format!(
"",
+ Implementations on Foreign Types",
res.into_iter()
.map(|(name, id)| format!("{}", id, Escape(&name)))
.collect::>()
@@ -4339,7 +4341,7 @@ fn sidebar_trait(buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
if t.auto {
sidebar.push_str(
"",
+ href=\"#synthetic-implementors\">Auto Implementors",
);
}
@@ -4365,18 +4367,18 @@ fn sidebar_typedef(buf: &mut Buffer, it: &clean::Item) {
}
fn get_struct_fields_name(fields: &[clean::Item]) -> String {
- fields
+ let mut fields = fields
.iter()
.filter(|f| if let clean::StructFieldItem(..) = f.inner { true } else { false })
.filter_map(|f| match f.name {
- Some(ref name) => Some(format!(
- "\
- {name}",
- name = name
- )),
+ Some(ref name) => {
+ Some(format!("{name}", name = name))
+ }
_ => None,
})
- .collect()
+ .collect::>();
+ fields.sort();
+ fields.join("")
}
fn sidebar_union(buf: &mut Buffer, it: &clean::Item, u: &clean::Union) {
@@ -4386,7 +4388,7 @@ fn sidebar_union(buf: &mut Buffer, it: &clean::Item, u: &clean::Union) {
if !fields.is_empty() {
sidebar.push_str(&format!(
"\
- ",
+ ",
fields
));
}
@@ -4401,23 +4403,20 @@ fn sidebar_union(buf: &mut Buffer, it: &clean::Item, u: &clean::Union) {
fn sidebar_enum(buf: &mut Buffer, it: &clean::Item, e: &clean::Enum) {
let mut sidebar = String::new();
- let variants = e
+ let mut variants = e
.variants
.iter()
.filter_map(|v| match v.name {
- Some(ref name) => Some(format!(
- "{name}\
- ",
- name = name
- )),
+ Some(ref name) => Some(format!("{name}", name = name)),
_ => None,
})
- .collect::();
+ .collect::>();
if !variants.is_empty() {
+ variants.sort_unstable();
sidebar.push_str(&format!(
"\
- ",
- variants
+ ",
+ variants.join(""),
));
}