Skip to content

Commit f134ca3

Browse files
authored
Rollup merge of #83051 - GuillaumeGomez:sidebar-trait-items-order, r=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``
2 parents 673d0db + 801ee83 commit f134ca3

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/librustdoc/html/render/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2122,22 +2122,22 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21222122
items: &[clean::Item],
21232123
before: &str,
21242124
filter: impl Fn(&clean::Item) -> bool,
2125-
write: impl Fn(&mut Buffer, &Symbol),
2125+
write: impl Fn(&mut Buffer, &str),
21262126
after: &str,
21272127
) {
21282128
let mut items = items
21292129
.iter()
21302130
.filter_map(|m| match m.name {
2131-
Some(ref name) if filter(m) => Some(name),
2131+
Some(ref name) if filter(m) => Some(name.as_str()),
21322132
_ => None,
21332133
})
21342134
.collect::<Vec<_>>();
21352135

21362136
if !items.is_empty() {
2137-
items.sort();
2137+
items.sort_unstable();
21382138
out.push_str(before);
21392139
for item in items.into_iter() {
2140-
write(out, item);
2140+
write(out, &item);
21412141
}
21422142
out.push_str(after);
21432143
}

src/test/rustdoc-gui/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,19 @@ pub fn some_more_function<T: fmt::Debug>(t: &T) -> String {
4747

4848
/// Woohoo! A trait!
4949
pub trait AnotherOne {
50+
/// Some func 3.
51+
fn func3();
52+
5053
/// Some func 1.
5154
fn func1();
5255

56+
fn another();
57+
fn why_not();
58+
5359
/// Some func 2.
5460
fn func2();
5561

56-
/// Some func 3.
57-
fn func3();
62+
fn hello();
5863
}
5964

6065
/// Check for "i" signs in lists!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
goto: file://|DOC_PATH|/trait.AnotherOne.html
2+
assert: (".sidebar-links a:nth-of-type(1)", "another")
3+
assert: (".sidebar-links a:nth-of-type(2)", "func1")
4+
assert: (".sidebar-links a:nth-of-type(3)", "func2")
5+
assert: (".sidebar-links a:nth-of-type(4)", "func3")
6+
assert: (".sidebar-links a:nth-of-type(5)", "hello")
7+
assert: (".sidebar-links a:nth-of-type(6)", "why_not")

0 commit comments

Comments
 (0)