Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustdoc] Sort impl associated items by kinds and then by appearance #129471

Merged
merged 6 commits into from
Sep 5, 2024

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 23, 2024

Following this zulip discussion, I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:

  1. Constants
  2. Types
  3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc @camelid
r? @notriddle

@GuillaumeGomez GuillaumeGomez added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Aug 23, 2024
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 23, 2024
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[2]/h4' \
// 'pub const X: u8 = 12u8'
pub const X: u8 = 12;
//@ has - '//*[@id="implementations-list"]//*[@class="impl-items"]/section[1]/h4' \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: in XPath, indexes start at 1, not 0.

@notriddle
Copy link
Contributor

Seems okay.

@rfcbot poll

@rfcbot
Copy link

rfcbot commented Aug 24, 2024

Team member @notriddle has asked teams: T-rustdoc-frontend, for consensus on:

@camelid
Copy link
Member

camelid commented Aug 25, 2024

I understand the principle of putting types first, but I feel like the more common style is constants, then types, then functions. It's also probably more common to use constants in types, mostly array lengths.

@notriddle
Copy link
Contributor

@rfcbot concern is-this-the-right-order

I understand the principle of putting types first, but I feel like the more common style is constants, then types, then functions. It's also probably more common to use constants in types, mostly array lengths.

That's fine, as long as the sidebar also gets fixed to use the same order.

@GuillaumeGomez
Copy link
Member Author

Dully noted. Thanks for pointing to the location!

@camelid
Copy link
Member

camelid commented Aug 25, 2024

@GuillaumeGomez could you also upload a demo to crud? It'd be nice to see how it looks once it's finalized.

@GuillaumeGomez
Copy link
Member Author

Sure! I uploaded doc here.

@GuillaumeGomez
Copy link
Member Author

Updated the order: constants now come first, followed by types and then methods.

@notriddle
Copy link
Contributor

notriddle commented Aug 25, 2024

Sidebar in https://rustdoc.crud.net/imperio/sort-impl-associated-items/bar/trait.Foo.html disagrees with page content.

screenshot

image

Sidebar in https://rustdoc.crud.net/imperio/sort-impl-associated-items/bar/struct.Bar.html has no type Y at all.

screenshot

image

@GuillaumeGomez
Copy link
Member Author

I keep forgetting that sidebar items are not generated at the same time as the page items. Maybe we should change that to prevent such case to happen again... I used this opportunity to add a test checking orders in the sidebar as well and updated the demo too.

Thanks @notriddle !

@camelid
Copy link
Member

camelid commented Sep 3, 2024

This looks pretty good, but I do wonder if it'd be better to just have gaps between the sidebar sections instead of headers. The headers are confusing because they all go to the same place, and they also add clutter. It should be fairly obvious to users what's what because of naming conventions (SNAKE_CASE for constants, CamelCase for types, and snake_case for methods).

@GuillaumeGomez
Copy link
Member Author

Isn't it out-of-scope here? This PR doesn't change the headers after all. Might be worth debating this in another issue, don't you think?

@camelid
Copy link
Member

camelid commented Sep 3, 2024

You're totally right, it is out of scope ^^'. For some reason I forgot that we already have those headers -- I guess just used to seeing only "Methods". Checking my box now...

@camelid
Copy link
Member

camelid commented Sep 3, 2024

We now have 3/4 approval, so this should be good to go now I think.

@GuillaumeGomez
Copy link
Member Author

Yes, just need to wait for @notriddle's concern to be resolved. Also, please don't hesitate to open an issue if you think it's something we should talk about (the headers).

@notriddle
Copy link
Contributor

My concern is resolved.

@GuillaumeGomez
Copy link
Member Author

Perfect, then time to r+ it. Thanks everyone!

@bors r=t-rustdoc-frontend rollup

@bors
Copy link
Contributor

bors commented Sep 3, 2024

📌 Commit 4a80840 has been approved by t-rustdoc-frontend

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 3, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 3, 2024
…d-items, r=t-rustdoc-frontend

[rustdoc] Sort impl associated items by kinds and then by appearance

Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:
1. Constants
2. Types
3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc `@camelid`
r? `@notriddle`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 3, 2024
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#127021 (Add target support for RTEMS Arm)
 - rust-lang#128871 (bypass linker configuration and cross target check for specific commands)
 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)
 - rust-lang#129529 (Add test to build crates used by r-a on stable)
 - rust-lang#129706 (Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir)
 - rust-lang#129796 (Unify scraped examples with other code examples)
 - rust-lang#129939 (explain why Rvalue::Len still exists)

r? `@ghost`
`@rustbot` modify labels: rollup
tgross35 added a commit to tgross35/rust that referenced this pull request Sep 4, 2024
…d-items, r=t-rustdoc-frontend

[rustdoc] Sort impl associated items by kinds and then by appearance

Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:
1. Constants
2. Types
3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc ``@camelid``
r? ``@notriddle``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 5, 2024
…d-items, r=t-rustdoc-frontend

[rustdoc] Sort impl associated items by kinds and then by appearance

Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:
1. Constants
2. Types
3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc ```@camelid```
r? ```@notriddle```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 5, 2024
…d-items, r=t-rustdoc-frontend

[rustdoc] Sort impl associated items by kinds and then by appearance

Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:
1. Constants
2. Types
3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc ````@camelid````
r? ````@notriddle````
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#128919 (Add an internal lint that warns when accessing untracked data)
 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)
 - rust-lang#129653 (clarify that addr_of creates read-only pointers)
 - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails)
 - rust-lang#129939 (explain why Rvalue::Len still exists)
 - rust-lang#129940 (s390x: Fix a regression related to backchain feature)
 - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc)
 - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test)
 - rust-lang#129944 (Add compat note for trait solver change)
 - rust-lang#129947 (Add digit separators in `Duration` examples)
 - rust-lang#129955 (Temporarily remove fmease from the review rotation)
 - rust-lang#129957 (forward linker option to lint-docs)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#128919 (Add an internal lint that warns when accessing untracked data)
 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)
 - rust-lang#129653 (clarify that addr_of creates read-only pointers)
 - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails)
 - rust-lang#129939 (explain why Rvalue::Len still exists)
 - rust-lang#129940 (s390x: Fix a regression related to backchain feature)
 - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc)
 - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test)
 - rust-lang#129944 (Add compat note for trait solver change)
 - rust-lang#129947 (Add digit separators in `Duration` examples)
 - rust-lang#129955 (Temporarily remove fmease from the review rotation)
 - rust-lang#129957 (forward linker option to lint-docs)

r? `@ghost`
`@rustbot` modify labels: rollup
@GuillaumeGomez GuillaumeGomez force-pushed the sort-impl-associated-items branch from 4a80840 to 8f9c4b3 Compare September 5, 2024 10:33
@GuillaumeGomez
Copy link
Member Author

Fixed merge conflict.

@bors r=t-rustdoc-frontend

@bors
Copy link
Contributor

bors commented Sep 5, 2024

📌 Commit 8f9c4b3 has been approved by t-rustdoc-frontend

It is now in the queue for this repository.

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#128919 (Add an internal lint that warns when accessing untracked data)
 - rust-lang#129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined)
 - rust-lang#129653 (clarify that addr_of creates read-only pointers)
 - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails)
 - rust-lang#129939 (explain why Rvalue::Len still exists)
 - rust-lang#129940 (s390x: Fix a regression related to backchain feature)
 - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc)
 - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test)
 - rust-lang#129944 (Add compat note for trait solver change)
 - rust-lang#129947 (Add digit separators in `Duration` examples)
 - rust-lang#129955 (Temporarily remove fmease from the review rotation)
 - rust-lang#129957 (forward linker option to lint-docs)

Failed merges:

 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#128919 (Add an internal lint that warns when accessing untracked data)
 - rust-lang#129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined)
 - rust-lang#129653 (clarify that addr_of creates read-only pointers)
 - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails)
 - rust-lang#129939 (explain why Rvalue::Len still exists)
 - rust-lang#129940 (s390x: Fix a regression related to backchain feature)
 - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc)
 - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test)
 - rust-lang#129944 (Add compat note for trait solver change)
 - rust-lang#129947 (Add digit separators in `Duration` examples)
 - rust-lang#129955 (Temporarily remove fmease from the review rotation)
 - rust-lang#129957 (forward linker option to lint-docs)

Failed merges:

 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129529 (Add test to build crates used by r-a on stable)
 - rust-lang#129624 (Adjust `memchr` pinning and run `cargo update`)
 - rust-lang#129720 (Simplify DestProp memory management)
 - rust-lang#129796 (Unify scraped examples with other code examples)
 - rust-lang#129891 (Do not request sanitizers for naked functions)
 - rust-lang#129938 (Elaborate on deriving vs implementing `Copy`)

Failed merges:

 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 12 pull requests

Successful merges:

 - rust-lang#128919 (Add an internal lint that warns when accessing untracked data)
 - rust-lang#129472 (fix ICE when `asm_const` and `const_refs_to_static` are combined)
 - rust-lang#129653 (clarify that addr_of creates read-only pointers)
 - rust-lang#129775 (bootstrap: Try to track down why `initial_libdir` sometimes fails)
 - rust-lang#129939 (explain why Rvalue::Len still exists)
 - rust-lang#129940 (s390x: Fix a regression related to backchain feature)
 - rust-lang#129942 (copy rustc rustlib artifacts from ci-rustc)
 - rust-lang#129943 (use the bootstrapped compiler for `test-float-parse` test)
 - rust-lang#129944 (Add compat note for trait solver change)
 - rust-lang#129947 (Add digit separators in `Duration` examples)
 - rust-lang#129955 (Temporarily remove fmease from the review rotation)
 - rust-lang#129957 (forward linker option to lint-docs)

Failed merges:

 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 5, 2024
…d-items, r=t-rustdoc-frontend

[rustdoc] Sort impl associated items by kinds and then by appearance

Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:
1. Constants
2. Types
3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc `@camelid`
r? `@notriddle`
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128820 (fix: get llvm type of global val)
 - rust-lang#129028 (`impl_trait_overcaptures`: Don't worry about uncaptured contravariant lifetimes if they outlive a captured lifetime)
 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)
 - rust-lang#129706 (Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir)
 - rust-lang#129720 (Simplify DestProp memory management)
 - rust-lang#129796 (Unify scraped examples with other code examples)
 - rust-lang#129938 (Elaborate on deriving vs implementing `Copy`)
 - rust-lang#129973 (run_make_support: rename `Command::stdin` to `stdin_buf` and add `std{in,out,err}` config helpers)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128820 (fix: get llvm type of global val)
 - rust-lang#129028 (`impl_trait_overcaptures`: Don't worry about uncaptured contravariant lifetimes if they outlive a captured lifetime)
 - rust-lang#129471 ([rustdoc] Sort impl associated items by kinds and then by appearance)
 - rust-lang#129706 (Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir)
 - rust-lang#129720 (Simplify DestProp memory management)
 - rust-lang#129796 (Unify scraped examples with other code examples)
 - rust-lang#129938 (Elaborate on deriving vs implementing `Copy`)
 - rust-lang#129973 (run_make_support: rename `Command::stdin` to `stdin_buf` and add `std{in,out,err}` config helpers)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6a23ee5 into rust-lang:master Sep 5, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 5, 2024
Rollup merge of rust-lang#129471 - GuillaumeGomez:sort-impl-associated-items, r=t-rustdoc-frontend

[rustdoc] Sort impl associated items by kinds and then by appearance

Following [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/.22Freeze.22.20order.20of.20items.20in.20.28trait.29.20impls.3F), I implemented it.

This brings the following change: impl associated items will now be grouped by kind and will now be first sorted by kind and then by the order they are declared in the source code (like currently).

The kinds are sorted in the following order:
1. Constants
2. Types
3. Functions

The reason behind this order is that associated constants can be used in associated types (like length in arrays) and both associated types and associated constants can be used in associated functions. So if an associated item from the same impl is used, its definition will always be above where it's being used.

cc ``@camelid``
r? ``@notriddle``
@GuillaumeGomez GuillaumeGomez deleted the sort-impl-associated-items branch September 6, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants