Skip to content

Commit

Permalink
Rollup merge of #83051 - GuillaumeGomez:sidebar-trait-items-order, r=…
Browse files Browse the repository at this point in the history
…CraftSpider,jyn514

Sidebar trait items order

We were actually sorting `Symbol` and not `String`, creating a completely invalid sort result. I added a test to prevent regressions.

r? ``@jyn514``
  • Loading branch information
Dylan-DPC committed Mar 24, 2021
2 parents 673d0db + 801ee83 commit f134ca3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/librustdoc/html/render/mod.rs
Expand Up @@ -2122,22 +2122,22 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
items: &[clean::Item],
before: &str,
filter: impl Fn(&clean::Item) -> bool,
write: impl Fn(&mut Buffer, &Symbol),
write: impl Fn(&mut Buffer, &str),
after: &str,
) {
let mut items = items
.iter()
.filter_map(|m| match m.name {
Some(ref name) if filter(m) => Some(name),
Some(ref name) if filter(m) => Some(name.as_str()),
_ => None,
})
.collect::<Vec<_>>();

if !items.is_empty() {
items.sort();
items.sort_unstable();
out.push_str(before);
for item in items.into_iter() {
write(out, item);
write(out, &item);
}
out.push_str(after);
}
Expand Down
9 changes: 7 additions & 2 deletions src/test/rustdoc-gui/lib.rs
Expand Up @@ -47,14 +47,19 @@ pub fn some_more_function<T: fmt::Debug>(t: &T) -> String {

/// Woohoo! A trait!
pub trait AnotherOne {
/// Some func 3.
fn func3();

/// Some func 1.
fn func1();

fn another();
fn why_not();

/// Some func 2.
fn func2();

/// Some func 3.
fn func3();
fn hello();
}

/// Check for "i" signs in lists!
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/trait-sidebar-item-order.goml
@@ -0,0 +1,7 @@
goto: file://|DOC_PATH|/trait.AnotherOne.html
assert: (".sidebar-links a:nth-of-type(1)", "another")
assert: (".sidebar-links a:nth-of-type(2)", "func1")
assert: (".sidebar-links a:nth-of-type(3)", "func2")
assert: (".sidebar-links a:nth-of-type(4)", "func3")
assert: (".sidebar-links a:nth-of-type(5)", "hello")
assert: (".sidebar-links a:nth-of-type(6)", "why_not")

0 comments on commit f134ca3

Please sign in to comment.