Skip to content

rustdoc: don't link doc(hidden) associated type projections#157438

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
qaijuang:rustdoc-hidden-assoc-type-link
Jun 5, 2026
Merged

rustdoc: don't link doc(hidden) associated type projections#157438
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
qaijuang:rustdoc-hidden-assoc-type-link

Conversation

@qaijuang

@qaijuang qaijuang commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Rustdoc renders associated type projections like T::Foo by linking Foo to the containing trait page and appending #associatedtype.Foo.

For #[doc(hidden)] associated types, that anchor is not rendered in normal docs, so this can produce dangling links.

This PR checks the corresponding trait associated item before emitting the projection link.
When the associated type is hidden, rustdoc leaves the projection text plain, accounting for --document-hidden-items as well.

Fixes #151454.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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 Jun 4, 2026
@qaijuang qaijuang marked this pull request as ready for review June 4, 2026 17:21
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 4, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 4, 2026
@rustbot

rustbot commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: rustdoc
  • rustdoc expanded to 9 candidates
  • Random selection from GuillaumeGomez, camelid, lolbinarycat, notriddle

@notriddle

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8e63eff has been approved by notriddle

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Jun 5, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 5, 2026
…-link, r=notriddle

rustdoc: don't link doc(hidden) associated type projections

Rustdoc renders associated type projections like `T::Foo` by linking `Foo` to the containing trait page and appending `#associatedtype.Foo`.

For `#[doc(hidden)]` associated types, that anchor is not rendered in normal docs, so this can produce dangling links.

This PR checks the corresponding trait associated item before emitting the projection link.
When the associated type is hidden, rustdoc leaves the projection text plain, accounting for `--document-hidden-items` as well.

Fixes rust-lang#151454.
rust-bors Bot pushed a commit that referenced this pull request Jun 5, 2026
Rollup of 12 pull requests

Successful merges:

 - #155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets)
 - #156798 (delegation: do not always generate first argument)
 - #157438 (rustdoc: don't link doc(hidden) associated type projections)
 - #157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`)
 - #148183 (rustdoc: Test & document `test_harness` code block attribute)
 - #157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages)
 - #157396 (Add @aapoalas to libs review rotation)
 - #157470 (Avoid ICE when emitting TargetMachine config errors)
 - #157474 (Forbid optimize(none) with inline(always) or inline.)
 - #157475 (Add a smoke test for the optimize attribute.)
 - #157479 (Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root)
 - #157486 (Remove unused attributes from issue-29485.rs.)

Failed merges:

 - #157485 (Rename `errors.rs` file to `diagnostics.rs`)
rust-bors Bot pushed a commit that referenced this pull request Jun 5, 2026
Rollup of 12 pull requests

Successful merges:

 - #157467 (stdarch subtree update)
 - #155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets)
 - #156798 (delegation: do not always generate first argument)
 - #157438 (rustdoc: don't link doc(hidden) associated type projections)
 - #157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`)
 - #157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages)
 - #157396 (Add @aapoalas to libs review rotation)
 - #157470 (Avoid ICE when emitting TargetMachine config errors)
 - #157474 (Forbid optimize(none) with inline(always) or inline.)
 - #157475 (Add a smoke test for the optimize attribute.)
 - #157479 (Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root)
 - #157486 (Remove unused attributes from issue-29485.rs.)

Failed merges:

 - #157485 (Rename `errors.rs` file to `diagnostics.rs`)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 5, 2026
…-link, r=notriddle

rustdoc: don't link doc(hidden) associated type projections

Rustdoc renders associated type projections like `T::Foo` by linking `Foo` to the containing trait page and appending `#associatedtype.Foo`.

For `#[doc(hidden)]` associated types, that anchor is not rendered in normal docs, so this can produce dangling links.

This PR checks the corresponding trait associated item before emitting the projection link.
When the associated type is hidden, rustdoc leaves the projection text plain, accounting for `--document-hidden-items` as well.

Fixes rust-lang#151454.
// Regression test for https://github.com/rust-lang/rust/issues/151454.
//@ has foo/fn.hidden_projection.html
//@ has - '//pre[@class="rust item-decl"]' 'T::Foo'
//@ !has - '//pre[@class="rust item-decl"]//a[@href="trait.Trait.html#associatedtype.Foo"]' 'Foo'

@GuillaumeGomez GuillaumeGomez Jun 5, 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.

Would likely have been better to check that there is a Foo element but not in a link. !has is very bad for DOM changes.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i can make a follow up PR on this, if you don't mind?

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.

Go ahead!

@rust-bors rust-bors Bot merged commit ccbad06 into rust-lang:main Jun 5, 2026
12 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 5, 2026
@qaijuang qaijuang deleted the rustdoc-hidden-assoc-type-link branch June 6, 2026 07:34
@qaijuang qaijuang mentioned this pull request Jun 7, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 7, 2026
rust-timer added a commit that referenced this pull request Jun 8, 2026
Rollup merge of #157581 - qaijuang:157438-follow-up, r=GuillaumeGomez

Test fixup

Follow up to #157438.

r? @GuillaumeGomez
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jun 8, 2026
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#157467 (stdarch subtree update)
 - rust-lang/rust#155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets)
 - rust-lang/rust#156798 (delegation: do not always generate first argument)
 - rust-lang/rust#157438 (rustdoc: don't link doc(hidden) associated type projections)
 - rust-lang/rust#157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`)
 - rust-lang/rust#157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages)
 - rust-lang/rust#157396 (Add @aapoalas to libs review rotation)
 - rust-lang/rust#157470 (Avoid ICE when emitting TargetMachine config errors)
 - rust-lang/rust#157474 (Forbid optimize(none) with inline(always) or inline.)
 - rust-lang/rust#157475 (Add a smoke test for the optimize attribute.)
 - rust-lang/rust#157479 (Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root)
 - rust-lang/rust#157486 (Remove unused attributes from issue-29485.rs.)

Failed merges:

 - rust-lang/rust#157485 (Rename `errors.rs` file to `diagnostics.rs`)
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Jun 8, 2026
asukaminato0721 pushed a commit to asukaminato0721/rust-analyzer that referenced this pull request Jun 8, 2026
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 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.

rustdoc creates links to doc(hidden) associated type

4 participants