rustdoc: Fix trait impl ordering#157233
Conversation
|
It's not ideal that this change didn't require any test changes. I know very little about rustdoc testing so I'm not sure where/how to add tests for this. |
|
The tool we use for XPaths in For the main section, the selector is |
2665e2a to
a43bb36
Compare
|
Some changes occurred in GUI tests. |
|
I have added a new test. Thanks for the rustdoc-gui tips, they were very helpful. |
This comment has been minimized.
This comment has been minimized.
a43bb36 to
7a6efc5
Compare
This shows how the ordering in the sidebar and the main section differ. The next commit will fix this inconsistency.
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.
7a6efc5 to
eef3ae7
Compare
|
Thanks! @bors r+ rollup |
…uwer Rollup of 14 pull requests Successful merges: - #156467 (mark the 'import linkage' statics as unnamed_addr) - #156923 (Couple of diagnostics improvements for EII) - #157240 (Enable Enzyme for aarch64-apple-darwin) - #157244 (Privacy: tweak macros + more tests) - #157276 (miri subtree update) - #157130 (Use a `ArrayVec` in `CastTarget`) - #157131 (Add regression test for issue #144888) - #157195 (Move feature gating to the new attr parsing infrastructure) - #157233 (rustdoc: Fix trait impl ordering) - #157256 (tests: adapt for LLVM codegen change) - #157265 (Update books) - #157277 (triagebot.toml: add LawnGnome to libs reviewers) - #157291 (Clean up attribute target checking diagnostics) - #157301 (Remove unused import from a test)
…uwer Rollup of 14 pull requests Successful merges: - #156467 (mark the 'import linkage' statics as unnamed_addr) - #156923 (Couple of diagnostics improvements for EII) - #157240 (Enable Enzyme for aarch64-apple-darwin) - #157244 (Privacy: tweak macros + more tests) - #157276 (miri subtree update) - #157130 (Use a `ArrayVec` in `CastTarget`) - #157131 (Add regression test for issue #144888) - #157195 (Move feature gating to the new attr parsing infrastructure) - #157233 (rustdoc: Fix trait impl ordering) - #157256 (tests: adapt for LLVM codegen change) - #157265 (Update books) - #157277 (triagebot.toml: add LawnGnome to libs reviewers) - #157291 (Clean up attribute target checking diagnostics) - #157301 (Remove unused import from a test)
Rollup merge of #157233 - nnethercote:rustdoc-impl-order, r=GuillaumeGomez rustdoc: Fix trait impl ordering 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. r? @GuillaumeGomez
|
@rust-timer build 0f41b4a |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (0f41b4a): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 5.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.1%, secondary -1.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 510.625s -> 511.417s (0.16%) |
|
This PR caused the regression in #157303 |
For types, rustdoc produces different impl orderings in the sidebar vs. the main section.
E.g. for
std::cell::UnsafeCellthe "Trait Implementations" sidebar order is this:The primary sort is on polarity, and the secondary sort is alphabetical. Makes sense.
The main section order is this:
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 formimpl-{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_keyshared between the two parts.r? @GuillaumeGomez