From 5e81325ca4057bf6b40f8a366aa95019559f9844 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 12 Mar 2021 12:19:31 +0100 Subject: [PATCH 1/3] Fix sidebar trait items sort --- src/librustdoc/html/render/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 128eac8cb0a51..e72b3f80bc290 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2122,19 +2122,19 @@ 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, String), 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.to_string()), _ => None, }) .collect::>(); if !items.is_empty() { - items.sort(); + items.sort_unstable(); out.push_str(before); for item in items.into_iter() { write(out, item); From 724590395001d3203903fa1a13b08d12ace56304 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 12 Mar 2021 14:25:01 +0100 Subject: [PATCH 2/3] Add test to enforce sidebar trait items order --- src/test/rustdoc-gui/lib.rs | 9 +++++++-- src/test/rustdoc-gui/trait-sidebar-item-order.goml | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/test/rustdoc-gui/trait-sidebar-item-order.goml diff --git a/src/test/rustdoc-gui/lib.rs b/src/test/rustdoc-gui/lib.rs index 15d8dcc6e8444..c5d9f0c5a6806 100644 --- a/src/test/rustdoc-gui/lib.rs +++ b/src/test/rustdoc-gui/lib.rs @@ -47,14 +47,19 @@ pub fn some_more_function(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! diff --git a/src/test/rustdoc-gui/trait-sidebar-item-order.goml b/src/test/rustdoc-gui/trait-sidebar-item-order.goml new file mode 100644 index 0000000000000..914486e1c281d --- /dev/null +++ b/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") From 801ee834654c2c30e27b4e37da6c7bcab05de6a3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 23 Mar 2021 17:36:36 +0100 Subject: [PATCH 3/3] Use &str instead of String --- src/librustdoc/html/render/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index e72b3f80bc290..05d30187aa853 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2122,13 +2122,13 @@ 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, String), + 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.to_string()), + Some(ref name) if filter(m) => Some(name.as_str()), _ => None, }) .collect::>(); @@ -2137,7 +2137,7 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean items.sort_unstable(); out.push_str(before); for item in items.into_iter() { - write(out, item); + write(out, &item); } out.push_str(after); }