Skip to content

Commit 4ba3796

Browse files
committed
Sort sidebar implementations on foreign types with natural compare
1 parent 9cd60bd commit 4ba3796

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/librustdoc/html/render/sidebar.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::clean;
1212
use crate::formats::Impl;
1313
use crate::formats::item_type::ItemType;
1414
use crate::html::markdown::{IdMap, MarkdownWithToc};
15+
use crate::html::render::print_item::compare_names;
1516

1617
#[derive(Clone, Copy)]
1718
pub(crate) enum ModuleLike {
@@ -297,7 +298,7 @@ fn sidebar_trait<'a>(
297298
.filter_map(|i| super::extract_for_impl_name(&i.impl_item, cx))
298299
.map(|(name, id)| Link::new(id, name)),
299300
);
300-
foreign_impls.sort();
301+
foreign_impls.sort_by(|a, b| compare_names(&a.name, &b.name));
301302
}
302303

303304
blocks.extend(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Checks sidebar resizing close the Settings popover
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/SidebarSort/trait.SidebarFoo.html#foreign-impls"
3+
4+
// Check that the sidebar contains the expected foreign implementations
5+
assert-text: (".sidebar-elems section ul > li:nth-child(1)", "&'a str")
6+
assert-text: (".sidebar-elems section ul > li:nth-child(2)", "AtomicBool")
7+
assert-text: (".sidebar-elems section ul > li:nth-child(3)", "AtomicU8")
8+
assert-text: (".sidebar-elems section ul > li:nth-child(4)", "AtomicU16")
9+
assert-text: (".sidebar-elems section ul > li:nth-child(5)", "AtomicU32")
10+
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Cell<u8>")
11+
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Cell<u16>")
12+
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "u8")
13+
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "u16")
14+
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "u32")
15+
assert-text: (".sidebar-elems section ul > li:nth-child(11)", "usize")

tests/rustdoc-gui/src/test_docs/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,21 @@ pub trait ItemsTrait {
713713
/// blablala
714714
fn bar();
715715
}
716+
717+
pub mod SidebarSort {
718+
use std::cell::Cell;
719+
use std::sync::atomic::*;
720+
pub trait SidebarFoo {}
721+
722+
impl SidebarFoo for u32 {}
723+
impl SidebarFoo for u8 {}
724+
impl SidebarFoo for u16 {}
725+
impl SidebarFoo for usize {}
726+
impl SidebarFoo for AtomicU32 {}
727+
impl SidebarFoo for AtomicU16 {}
728+
impl SidebarFoo for AtomicU8 {}
729+
impl SidebarFoo for AtomicBool {}
730+
impl SidebarFoo for Cell<u16> {}
731+
impl SidebarFoo for Cell<u8> {}
732+
impl<'a> SidebarFoo for &'a str {}
733+
}

0 commit comments

Comments
 (0)