Skip to content

Commit b711a2a

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

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
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

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! The point of this crate is to be able to have enough different "kinds" of
22
//! documentation generated so we can test each different features.
3-
#![doc(html_playground_url="https://play.rust-lang.org/")]
4-
3+
#![doc(html_playground_url = "https://play.rust-lang.org/")]
54
#![crate_name = "test_docs"]
65
#![allow(internal_features)]
76
#![feature(rustdoc_internals)]
@@ -343,18 +342,17 @@ pub trait EmptyTrait1 {}
343342
pub trait EmptyTrait2 {}
344343
pub trait EmptyTrait3 {}
345344

346-
pub struct HasEmptyTraits{}
345+
pub struct HasEmptyTraits {}
347346

348347
impl EmptyTrait1 for HasEmptyTraits {}
349348
impl EmptyTrait2 for HasEmptyTraits {}
350349
#[doc(cfg(feature = "some-feature"))]
351350
impl EmptyTrait3 for HasEmptyTraits {}
352351

353352
mod macros;
354-
pub use macros::*;
355-
356353
#[doc(alias = "AliasForTheStdReexport")]
357354
pub use ::std as TheStdReexport;
355+
pub use macros::*;
358356

359357
pub mod details {
360358
/// We check the appearance of the `<details>`/`<summary>` in here.
@@ -406,19 +404,22 @@ pub mod doc_block_table {
406404
println!();
407405
}
408406
}
409-
410407
}
411408

412409
pub struct NotableStructWithLongName<R>(R);
413410

414411
impl<R: std::io::Read> NotableStructWithLongName<R> {
415-
pub fn create_an_iterator_from_read(r: R) -> NotableStructWithLongName<R> { Self(r) }
412+
pub fn create_an_iterator_from_read(r: R) -> NotableStructWithLongName<R> {
413+
Self(r)
414+
}
416415
}
417416

418417
impl<R: std::io::Read> std::iter::Iterator for NotableStructWithLongName<R> {
419418
type Item = ();
420419

421-
fn next(&mut self) -> Option<Self::Item> { () }
420+
fn next(&mut self) -> Option<Self::Item> {
421+
()
422+
}
422423
}
423424

424425
pub trait TraitWithNoDocblocks {
@@ -527,7 +528,6 @@ pub mod search_results {
527528
macro_rules! foo {
528529
() => {};
529530
}
530-
531531
}
532532

533533
pub mod fields {
@@ -540,14 +540,8 @@ pub mod fields {
540540
pub b: u32,
541541
}
542542
pub enum Enum {
543-
A {
544-
a: u8,
545-
b: u32,
546-
},
547-
B {
548-
a: u8,
549-
b: u32,
550-
},
543+
A { a: u8, b: u32 },
544+
B { a: u8, b: u32 },
551545
}
552546
}
553547

@@ -713,3 +707,21 @@ pub trait ItemsTrait {
713707
/// blablala
714708
fn bar();
715709
}
710+
711+
pub mod SidebarSort {
712+
use std::cell::Cell;
713+
use std::sync::atomic::*;
714+
pub trait SidebarFoo {}
715+
716+
impl SidebarFoo for u32 {}
717+
impl SidebarFoo for u8 {}
718+
impl SidebarFoo for u16 {}
719+
impl SidebarFoo for usize {}
720+
impl SidebarFoo for AtomicU32 {}
721+
impl SidebarFoo for AtomicU16 {}
722+
impl SidebarFoo for AtomicU8 {}
723+
impl SidebarFoo for AtomicBool {}
724+
impl SidebarFoo for Cell<u16> {}
725+
impl SidebarFoo for Cell<u8> {}
726+
impl<'a> SidebarFoo for &'a str {}
727+
}

0 commit comments

Comments
 (0)