mirror of
https://github.com/rust-lang/rust.git
synced 2026-07-22 07:36:35 -04:00
eef3ae7817
For types, rustdoc produces different impl orderings in the sidebar vs.
the main section.
E.g. for `std::cell::UnsafeCell` the "Trait Implementations" sidebar
order is this:
```
!Freeze
!RefUnwindSafe
!Sync
CoerceUnsized<UnsafeCell<U>>
Debug
Default
DispatchFromDyn<UnsafeCell<U>>
From<T>
```
The primary sort is on polarity, and the secondary sort is alphabetical.
Makes sense.
The main section order is this:
```
impl<T> Debug for UnsafeCell<T>
impl<T> Default for UnsafeCell<T>
impl<T> From<T> for UnsafeCell<T>
impl<T, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T>
impl<T, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T>
impl<T> !Freeze for UnsafeCell<T>
impl<T> !RefUnwindSafe for UnsafeCell<T>
impl<T> !Sync for UnsafeCell<T>
```
This strange ordering occurs because the entries are sorted on the
generated HTML. Impls with methods (the first three) come first because
they start with a `<details>` tag while the others start with a
`<section>` tag. After that, the order depends on a section id of the
form `impl-{trait}-for-{type}` that doesn't include the polarity, which
is why the secondary ordering is alphabetical but ignores the `!`.
The sidebar ordering is the better of the two. This commit changes the
main section to use the same ordering as the sidebar. This involves
creating a new function `impl_trait_key` shared between the two parts.
20 lines
1.3 KiB
Plaintext
20 lines
1.3 KiB
Plaintext
// Check that trait impls in the sidebar and the main section have the same
|
|
// ordering.
|
|
|
|
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
|
|
|
|
// .sidebar .trait-implementation li:nth-child(3) a
|
|
assert-text: (".sidebar-elems .trait-implementation li:nth-child(1) a", "!Sync")
|
|
assert-text: (".sidebar-elems .trait-implementation li:nth-child(2) a", "AsRef<str>")
|
|
assert-text: (".sidebar-elems .trait-implementation li:nth-child(3) a", "From<u8>")
|
|
assert-text: (".sidebar-elems .trait-implementation li:nth-child(4) a", "From<u16>")
|
|
assert-text: (".sidebar-elems .trait-implementation li:nth-child(5) a", "From<u32>")
|
|
assert-text: (".sidebar-elems .trait-implementation li:nth-child(6) a", "Send")
|
|
|
|
assert-text: ("#trait-implementations-list section:nth-child(1) .code-header", "impl !Sync for Foo")
|
|
assert-text: ("#trait-implementations-list details:nth-child(2) .code-header", "impl AsRef<str> for Foo")
|
|
assert-text: ("#trait-implementations-list details:nth-child(3) .code-header", "impl From<u8> for Foo")
|
|
assert-text: ("#trait-implementations-list details:nth-child(4) .code-header", "impl From<u16> for Foo")
|
|
assert-text: ("#trait-implementations-list details:nth-child(5) .code-header", "impl From<u32> for Foo")
|
|
assert-text: ("#trait-implementations-list section:nth-child(6) .code-header", "impl Send for Foo")
|