Skip to content

Enable --generate-link-to-definition rustdoc option on std docs - #162808

Open
GuillaumeGomez wants to merge 5 commits into
rust-lang:mainfrom
GuillaumeGomez:std-link-to-def
Open

GuillaumeGomez wants to merge 5 commits into
rust-lang:mainfrom
GuillaumeGomez:std-link-to-def

Conversation

@GuillaumeGomez

@GuillaumeGomez GuillaumeGomez commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

View all comments

In the future (unclear at which point), rustdoc plans to get closer to the rust compiler and compile more of the code, making the std code not compile anymore because of all the cfg(doc) in it to present a unified API to our users. To fix it (although incompletely), we can use the --generate-link-to-definition rustdoc option (which we already use in the compiler docs) which requires to query more information and fails with current std code. This PR fixes these errors and prevent regressions by enabling the new rustdoc option.

r? @Amanieu

@rustbot rustbot added O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-linux Operating system: Linux O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 15, 2026
Comment thread library/std/src/lib.rs Outdated
$($code)*
}
#[cfg(doc)]
loop {}

@GuillaumeGomez GuillaumeGomez Sep 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a little hack to ensure that the code is not compiled and won't fail compilation whatever the return type since loop returns !.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Sep 15, 2026
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Seems like some work remains. Gonna convert it to draft for the time being.

@GuillaumeGomez
GuillaumeGomez marked this pull request as draft September 15, 2026 14:33
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 20, 2026
…Urgau

[rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature

Part of the missing pieces for rust-lang#162808 to work.

The issue was that in case we had the method of a dyn trait, we tried to use the dyn trait as is and couldn't generate a correct href to its `DefId`. If we get the trait in the `dyn`, it works just as expected.

r? @Urgau
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
Rollup merge of #163036 - GuillaumeGomez:dyn-jump-to-def, r=Urgau

[rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature

Part of the missing pieces for #162808 to work.

The issue was that in case we had the method of a dyn trait, we tried to use the dyn trait as is and couldn't generate a correct href to its `DefId`. If we get the trait in the `dyn`, it works just as expected.

r? @Urgau
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 25, 2026
… r=Urgau

[rustdoc] Correctly check that an item is not `doc(hidden)` with `--generate-link-to-definition`

Needed for rust-lang#162808.

The problem was that we only checked the item itself, not any of its parents. Fixed by adding a loop.

r? @Urgau
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Rollup merge of #163268 - GuillaumeGomez:jump-to-def-hidden, r=Urgau

[rustdoc] Correctly check that an item is not `doc(hidden)` with `--generate-link-to-definition`

Needed for #162808.

The problem was that we only checked the item itself, not any of its parents. Fixed by adding a loop.

r? @Urgau
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 25, 2026
…ent, r=Urgau

[rustdoc] Fix invalid jump to def link when `#[rustc_allow_incoherent_impl]` is involved

Fixes rust-lang#163112.

Problem here is that the method is not available in the crate where the type is defined. So `def_path` is actually problematic here as it resolves to the end item, which is not what we want. So instead, I made a simplified version of the `rustc_middle::ty::print::pretty::try_print_visible_def_path_recur` function.

It's also needed for rust-lang#162808.

r? @Urgau
@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a39251d has been approved by Amanieu

It is now in the queue for this repository.

@bjorn3 bjorn3 Oct 26, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"everybody loops" returns?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand the question so I'll answer to "Is it an issue to use this attribute macro if the function returns something other than ()". Answer: loop returns !, so it covers every types. It's a little trick we used at some point in rustdoc to remove function bodies (before we realized you could have impl inside any block).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was referring to the old everybody loops pass that rustdoc used to have, but then removed because it broke with RPIT. Seems like we have pretty much gone full circle except now you have to opt-in to the loop replacement instead.

@JonathanBrouwer

Copy link
Copy Markdown
Member

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #165000 (comment)

@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#165000), which was unapproved.

View changes since this unapproval

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try jobs=test-aarch64-msvc-2,test-x86_64-msvc-1

@rust-bors

This comment has been minimized.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Wait, why is my new commit not there? And why is it "processing updates". Github...

@bors cancel

@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

❗ There is currently no auto build in progress on this PR.

Hint: There is a pending try build on this PR. Maybe you meant to cancel it? You can do that using @bors try cancel.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try cancel

@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Try build cancelled. Cancelled workflows:

Hint: if you want to run another try build, you do not need to manually cancel the previous one. Just run @bors try and bors will cancel the previous build automatically.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors try jobs=test-aarch64-msvc-2,test-x86_64-msvc-1

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: d4bb448 (d4bb4483838d5949ab8a87788a9b85170ae97c2e)
Base parent: 846e51f (846e51f66b1e7b49ba9e3988c58ccfe5817ce0a9)

@rustbot

rustbot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Rebased just in case.

Also let's retry the previous jobs.

@bors try jobs=test-aarch64-msvc-2,test-x86_64-msvc-1

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 03d6406 (03d64068769d4d9c80471f4da26af97100968c35)
Base parent: 16d1ffa (16d1ffac17ad8b739e32483ac2e65fe7e1804977)

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors r=Amanieu

@rust-bors

rust-bors Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6623b95 has been approved by Amanieu

It is now in the queue for this repository.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-apple Operating system: Apple / Darwin (macOS, iOS, tvOS, visionOS, watchOS) O-linux Operating system: Linux O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library 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.

8 participants