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: add unstable option --crate-list-heading to customize the sidebar crate list. #138143

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Mar 7, 2025

When used, this option creates a subheading within the sidebar “Crates” list for this crate and all crates which pass the same value. These headings are displayed in alphabetical order; crates without the option, or with it set to the empty string, always appear first.

The intended use of this option is to allow Cargo to automatically separate a workspace’s crate list into the workspace’s own crates and their external dependencies (as requested in #85759 and, loosely, #81031). Even without Cargo support, authors could also use RUSTDOCFLAGS to create custom headings for their documentation builds (which may address #16328).

As currently written, merging this would break all nightly builds against a pre-existing target/doc/, because the format of crates.js (defining variable window.ALL_CRATES) is changed. I don’t know whether backwards compatibility is worth implementing here, but it is possible to arrange — I figured I should first get a review of the general idea before polishing it.


Example of the new sidebar appearance in one of my workspaces:

image
Original obsolete version image

The vertical margins <h3>Dependencies</h3> should probably adjusted to have clearer visual hierarchy, but I don’t think that should be done in this PR. Also note that this additional header will not appear until explicitly requested via the flag — in this screenshot I am also using a patched Cargo.


@rustbot label A-rustdoc-ui T-rustdoc T-rustdoc-frontend

@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2025

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Mar 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2025

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha

@rustbot rustbot added the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Mar 7, 2025
@kpreid kpreid changed the title Rustdoc: add unstable option --crate-list-heading to customize the sidebar crate list. rustdoc: add unstable option --crate-list-heading to customize the sidebar crate list. Mar 7, 2025
@rust-log-analyzer

This comment has been minimized.

@kpreid kpreid force-pushed the crate-sidebar branch 2 times, most recently from 90486a8 to 61edefc Compare March 7, 2025 06:17
When used, this option creates a subheading within the sidebar
“Crates” list for this crate and all crates which pass the same value.
These headings are displayed in alphabetical order; crates without the
option, or with it set to the empty string, always appear first.

The intended use of this option is to allow Cargo to automatically
separate a workspace’s crate list into the workspace’s own crates
and their external dependencies. Authors could also use RUSTDOCFLAGS
or other means to create custom headings for their documentation builds.
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@notriddle notriddle left a comment

Choose a reason for hiding this comment

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

Overall, I'm fine with this direction. There are a few nits, but mostly I'm fine with it.

It's nice that Cargo can use this API, so it'll know about things like workspaces, but it's flexible enough that other projects like Linux can use it for their own purposes.

@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2025

Some changes occurred in src/tools/cargo

cc @ehuss

Some changes occurred in GUI tests.

cc @GuillaumeGomez

@kpreid
Copy link
Contributor Author

kpreid commented Mar 7, 2025

Ignore that Cargo ping; I accidentally pushed a submodule change (not sure what was going on; I had only uncommitted changes, but it seemed like one of the tests changed the submodule commit too).

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
.......... (130/137)
..FFFFF    (137/137)


/checkout/tests/rustdoc-gui/implementors.goml implementors... FAILED
[ERROR] `tests/rustdoc-gui/implementors.goml` line 33: expected 1 elements, found 2: for command `assert-count: ("#implementors-list .impl", 1)`

/checkout/tests/rustdoc-gui/sidebar-source-code-display.goml sidebar-source-code-display... FAILED
[ERROR] `tests/rustdoc-gui/sidebar-source-code-display.goml` line 24: ".sidebar a.selected" not found: for command `click: ".sidebar a.selected"`

/checkout/tests/rustdoc-gui/sidebar-source-code.goml sidebar-source-code... FAILED
[ERROR] `tests/rustdoc-gui/sidebar-source-code.goml` line 68: "//*[@class='dir-entry' and @open]/*[text()='lib2']" not found: for command `assert: "//*[@class='dir-entry' and @open]/*[text()='lib2']"`
[ERROR] `tests/rustdoc-gui/sidebar-source-code.goml` line 69: "//*[@class='dir-entry' and @open]/*[normalize-space()='another_folder']" not found: for command `assert: "//*[@class='dir-entry' and @open]/*[normalize-space()='another_folder']"`
[ERROR] `tests/rustdoc-gui/sidebar-source-code.goml` line 70: "//*[@class='dir-entry' and @open]/*[normalize-space()='sub_mod']" not found: for command `assert: "//*[@class='dir-entry' and @open]/*[normalize-space()='sub_mod']"`
[ERROR] `tests/rustdoc-gui/sidebar-source-code.goml` line 74: expected 11 elements, found 12: for command `assert-count: ("//*[@id='src-sidebar']/details[not(normalize-space()='lib2') and not(@open)]", 11)`
/checkout/tests/rustdoc-gui/source-code-page.goml source-code-page... FAILED
/checkout/tests/rustdoc-gui/source-code-page.goml source-code-page... FAILED
[ERROR] `tests/rustdoc-gui/source-code-page.goml` line 105: The following errors happened: [`[object Object]` isn't equal to `extend_css`]: for command `assert-text: ("#src-sidebar details:first-of-type > summary", "extend_css")`
/checkout/tests/rustdoc-gui/type-impls.goml type-impls... FAILED
/checkout/tests/rustdoc-gui/type-impls.goml type-impls... FAILED
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 9: "//*[@id='method.as_ref']" not found: for command `assert: "//*[@id='method.as_ref']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 10: "//*[@id='method.must_use']" not found: for command `assert: "//*[@id='method.must_use']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 11: "//*[@id='method.warning1']" not found: for command `assert: "//*[@id='method.warning1']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 12: "//*[@id='method.warning2']" not found: for command `assert: "//*[@id='method.warning2']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 15: "//*[@class='sidebar-elems']//li/a[@href='#method.must_use']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#method.must_use']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 17: "//*[@class='sidebar-elems']//li/a[@href='#method.warning1']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#method.warning1']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 18: "//*[@class='sidebar-elems']//li/a[@href='#method.warning2']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#method.warning2']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 19: "//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-Foo']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-Foo']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 22: The following errors happened: [`some_other_method_directly` isn't equal to `must_use`]: for command `assert-text: (".block.method li:nth-child(1)", 'must_use')`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 23: ".block.method li:nth-child(2)" not found: for command `assert-text: (".block.method li:nth-child(2)", 'some_other_method_directly')`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 24: ".block.method li:nth-child(3)" not found: for command `assert-text: (".block.method li:nth-child(3)", 'warning1')`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 25: ".block.method li:nth-child(4)" not found: for command `assert-text: (".block.method li:nth-child(4)", 'warning2')`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 34: "//*[@id='method.as_ref-1']" not found: for command `assert: "//*[@id='method.as_ref-1']"`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 41: "//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-UnderlyingFooBarBaz']" not found: for command `assert-text: ("//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-UnderlyingFooBarBaz']", "AsRef<str>")`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 47: expected 2 elements, found 1: for command `assert-count: ("#trait-implementations-list > details", 2)`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 50: "//*[@id='method.as_ref-1']//a[@class='fn']" not found: for command `assert-property: ("//*[@id='method.as_ref-1']//a[@class='fn']", {"href": |href|})`
[ERROR] `tests/rustdoc-gui/type-impls.goml` line 53: "//*[@id='method.as_ref-1']//a[@class='anchor'][@href='#method.as_ref-1']" not found: for command `assert: "//*[@id='method.as_ref-1']//a[@class='anchor'][@href='#method.as_ref-1']"`
Error: ()
Build completed unsuccessfully in 0:03:25
  local time: Sat Mar  8 00:43:16 UTC 2025
  network time: Sat, 08 Mar 2025 00:43:17 GMT

@kpreid
Copy link
Contributor Author

kpreid commented Mar 8, 2025

I do not understand the rustdoc-gui test failures here. Most of them seem unrelated to my change, and when I view the test documentation locally, it meets the criteria the tests are looking for. Also, some tests fail even without my change — did I perhaps pick a bad base revision and need to rebase?

  /checkout/tests/rustdoc-gui/implementors.goml implementors... FAILED
  Error:  `tests/rustdoc-gui/implementors.goml` line 33: expected 1 elements, found 2: for command `assert-count: ("#implementors-list .impl", 1)`
  
  /checkout/tests/rustdoc-gui/sidebar-source-code-display.goml sidebar-source-code-display... FAILED
  Error:  `tests/rustdoc-gui/sidebar-source-code-display.goml` line 24: ".sidebar a.selected" not found: for command `click: ".sidebar a.selected"`
  
  /checkout/tests/rustdoc-gui/sidebar-source-code.goml sidebar-source-code... FAILED
  Error:  `tests/rustdoc-gui/sidebar-source-code.goml` line 68: "//*[@class='dir-entry' and @open]/*[text()='lib2']" not found: for command `assert: "//*[@class='dir-entry' and @open]/*[text()='lib2']"`
  Error:  `tests/rustdoc-gui/sidebar-source-code.goml` line 69: "//*[@class='dir-entry' and @open]/*[normalize-space()='another_folder']" not found: for command `assert: "//*[@class='dir-entry' and @open]/*[normalize-space()='another_folder']"`
  Error:  `tests/rustdoc-gui/sidebar-source-code.goml` line 70: "//*[@class='dir-entry' and @open]/*[normalize-space()='sub_mod']" not found: for command `assert: "//*[@class='dir-entry' and @open]/*[normalize-space()='sub_mod']"`
  Error:  `tests/rustdoc-gui/sidebar-source-code.goml` line 74: expected 11 elements, found 12: for command `assert-count: ("//*[@id='src-sidebar']/details[not(normalize-space()='lib2') and not(@open)]", 11)`
  
  /checkout/tests/rustdoc-gui/source-code-page.goml source-code-page... FAILED
  Error:  `tests/rustdoc-gui/source-code-page.goml` line 105: The following errors happened: [`[object Object]` isn't equal to `extend_css`]: for command `assert-text: ("#src-sidebar details:first-of-type > summary", "extend_css")`
  
  /checkout/tests/rustdoc-gui/type-impls.goml type-impls... FAILED
  Error:  `tests/rustdoc-gui/type-impls.goml` line 9: "//*[@id='method.as_ref']" not found: for command `assert: "//*[@id='method.as_ref']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 10: "//*[@id='method.must_use']" not found: for command `assert: "//*[@id='method.must_use']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 11: "//*[@id='method.warning1']" not found: for command `assert: "//*[@id='method.warning1']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 12: "//*[@id='method.warning2']" not found: for command `assert: "//*[@id='method.warning2']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 15: "//*[@class='sidebar-elems']//li/a[@href='#method.must_use']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#method.must_use']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 17: "//*[@class='sidebar-elems']//li/a[@href='#method.warning1']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#method.warning1']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 18: "//*[@class='sidebar-elems']//li/a[@href='#method.warning2']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#method.warning2']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 19: "//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-Foo']" not found: for command `assert: "//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-Foo']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 22: The following errors happened: [`some_other_method_directly` isn't equal to `must_use`]: for command `assert-text: (".block.method li:nth-child(1)", 'must_use')`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 23: ".block.method li:nth-child(2)" not found: for command `assert-text: (".block.method li:nth-child(2)", 'some_other_method_directly')`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 24: ".block.method li:nth-child(3)" not found: for command `assert-text: (".block.method li:nth-child(3)", 'warning1')`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 25: ".block.method li:nth-child(4)" not found: for command `assert-text: (".block.method li:nth-child(4)", 'warning2')`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 34: "//*[@id='method.as_ref-1']" not found: for command `assert: "//*[@id='method.as_ref-1']"`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 41: "//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-UnderlyingFooBarBaz']" not found: for command `assert-text: ("//*[@class='sidebar-elems']//li/a[@href='#impl-AsRef%3Cstr%3E-for-UnderlyingFooBarBaz']", "AsRef<str>")`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 47: expected 2 elements, found 1: for command `assert-count: ("#trait-implementations-list > details", 2)`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 50: "//*[@id='method.as_ref-1']//a[@class='fn']" not found: for command `assert-property: ("//*[@id='method.as_ref-1']//a[@class='fn']", {"href": |href|})`
  Error:  `tests/rustdoc-gui/type-impls.goml` line 53: "//*[@id='method.as_ref-1']//a[@class='anchor'][@href='#method.as_ref-1']" not found: for command `assert: "//*[@id='method.as_ref-1']//a[@class='anchor'][@href='#method.as_ref-1']"`

@GuillaumeGomez
Copy link
Member

Do you have an example hosted somewhere by any chance so I can take a look?

@bors
Copy link
Contributor

bors commented Mar 13, 2025

☔ The latest upstream changes (presumably #138416) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. 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