Skip to content

Conversation

@camelid
Copy link
Member

@camelid camelid commented Jan 2, 2026

This PR:

  • Add support for linking to fields of variants behind a type alias.
  • Correctly resolve links to fields and variants behind a type alias to the alias's version of the docs.
  • Refactor some intra-doc links code to make it simpler.
  • Add tests for the status quo of linking to associated items behind aliases.

Future steps:

  • Nail down the rules of when inherent and trait impls are inlined into an alias's docs, and when impls on the alias appear for the aliased type.
  • Adjust the resolutions of intra-doc links, through aliases, to associated items based on these rules.

r? @GuillaumeGomez

@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 Jan 2, 2026
@GuillaumeGomez
Copy link
Member

Is it ready for review? (It's a draft so wondering ^^')

@camelid
Copy link
Member Author

camelid commented Jan 2, 2026

I'm planning to add one more commit, but it's mostly done.

@camelid
Copy link
Member Author

camelid commented Jan 2, 2026

It's best reviewed commit-by-commit btw since I moved a lot of code around.

@bors
Copy link
Collaborator

bors commented Jan 7, 2026

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

1 similar comment
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 7, 2026

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

Previously, these failed to resolve, despite them working for struct
fields or enum variants that were behind aliases.

However, there is now an inconsistency where enum variant fields behind
an alias resolve to the entry on the alias's page, while enum variants
and struct fields resolve to the page of the backing ADT.
The old name and API were confusing. In my opinion, looking up the type
at the call site is clearer.
All the other parts of this function return the Res for the containing
page, but for some reason, this returns the associated item itself. It
doesn't seem to affect the behavior of rustdoc because e.g. the href
functions use the parent if the DefId is for an assoc item. But it's
clearer and simpler to be consistent.
@camelid camelid force-pushed the intra-doc-assoc-alias branch 2 times, most recently from 2bd0b56 to 844ae64 Compare January 8, 2026 21:12
@camelid camelid marked this pull request as ready for review January 8, 2026 21:12
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 8, 2026
@camelid
Copy link
Member Author

camelid commented Jan 8, 2026

Ok, I think this is ready for review now. It doesn't fix all the inconsistencies with type aliases and associated items, but it does improve the status quo and adds some tests so we'll notice if/when we change things.

The rules around when impls from an aliased type are inlined into the alias's docs seem pretty arbitrary and inconsistent, so we should probably nail that down before we adjust where intra-doc links go.

@rust-log-analyzer

This comment has been minimized.

@camelid camelid force-pushed the intra-doc-assoc-alias branch from 844ae64 to 2b618ed Compare January 8, 2026 21:42
}

let search_for_field = || {
let (DefKind::Struct | DefKind::Union) = adt_def_kind else { return vec![] };
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't work for enum's variants with fields I guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's handled separately in the variant_field function. The reason there's a distinction is that paths to struct and union fields look the same as paths to enum variants and associated items (two segments), while paths to enum variant fields look different (three segments).

I agree that it's confusing that they're handled separately though. I think it would be simpler if we don't do this sort of path length-based separation.

Copy link
Member Author

@camelid camelid Jan 12, 2026

Choose a reason for hiding this comment

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

It looks like this length-based logic means that re-exports of variants don't work properly (can't look up their fields). Although this is a pre-existing bug, we should definitely try to fix it in a future PR.

Copy link
Member

Choose a reason for hiding this comment

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

Please open an issue. :)

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks! Just one question but otherwise seems ready to go.

View changes since this review

@camelid
Copy link
Member Author

camelid commented Jan 12, 2026

@bors r=GuillaumeGomez

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 12, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 12, 2026

📌 Commit 2b618ed has been approved by GuillaumeGomez

It is now in the queue for this repository.

@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 12, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 13, 2026
…Gomez

rustdoc: Fix intra-doc link bugs involving type aliases and associated items

This PR:
- Add support for linking to fields of variants behind a type alias.
- Correctly resolve links to fields and variants behind a type alias to the alias's version of the docs.
- Refactor some intra-doc links code to make it simpler.
- Add tests for the status quo of linking to associated items behind aliases.

Future steps:
- Nail down the rules of when inherent and trait impls are inlined into an alias's docs, and when impls on the alias appear for the aliased type.
- Adjust the resolutions of intra-doc links, through aliases, to associated items based on these rules.

r? @GuillaumeGomez
rust-bors bot pushed a commit that referenced this pull request Jan 13, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #150586 (rustdoc: Fix intra-doc link bugs involving type aliases and associated items)
 - #150677 (Improve std::path::Path::join documentation)
 - #150723 (std: move `errno` and related functions into `sys::io`)
 - #150737 (diagnostics: make implicit Sized bounds explicit in E0277)
 - #150771 (Remove legacy homu `try` and `auto` branch mentions)
 - #150915 (Regression test for type params on eii)
 - #150962 (Remove `FeedConstTy` and provide ty when lowering const arg)
 - #151017 (Port the rustc dump attributes to the attribute parser)
 - #151019 (Make `Type::of` support unsized types)
 - #151034 (std: Change UEFI env vars to volatile storage)
 - #151052 (ui: add regression test for macro resolution ICE (issue #150711))
 - #151053 (Reduce flakyness for `tests/rustdoc-gui/notable-trait.goml`)
 - #151055 (Emit error instead of delayed bug when meeting mismatch type for const array)

r? @ghost
@GuillaumeGomez
Copy link
Member

I think this is the one which failed in #151070 (if I'm wrong please re-r+ it and sorry for the noise).

@bors r-

@rust-bors rust-bors bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 13, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 13, 2026

Commit 2b618ed has been unapproved.

@JonathanBrouwer
Copy link
Contributor

JonathanBrouwer commented Jan 14, 2026

A rollup failed with the same error again, so this was probably incorrectly r-'ed
If this try job succeeds feel free to r+ again
@bors try jobs=dist-x86_64-linux-alt

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 14, 2026
rustdoc: Fix intra-doc link bugs involving type aliases and associated items


try-job: dist-x86_64-linux-alt
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 14, 2026

☀️ Try build successful (CI)
Build commit: 81367f2 (81367f222ae78ecdc58ce30bbe8de8f5887d2f68, parent: 4931e09e3ac3182d2a00f38cccfdf68e8e385e1c)

@JonathanBrouwer
Copy link
Contributor

@bors r=GuillaumeGomez

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 14, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 14, 2026

📌 Commit 2b618ed has been approved by GuillaumeGomez

It is now in the queue for this repository.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 14, 2026
…Gomez

rustdoc: Fix intra-doc link bugs involving type aliases and associated items

This PR:
- Add support for linking to fields of variants behind a type alias.
- Correctly resolve links to fields and variants behind a type alias to the alias's version of the docs.
- Refactor some intra-doc links code to make it simpler.
- Add tests for the status quo of linking to associated items behind aliases.

Future steps:
- Nail down the rules of when inherent and trait impls are inlined into an alias's docs, and when impls on the alias appear for the aliased type.
- Adjust the resolutions of intra-doc links, through aliases, to associated items based on these rules.

r? @GuillaumeGomez
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 14, 2026
…Gomez

rustdoc: Fix intra-doc link bugs involving type aliases and associated items

This PR:
- Add support for linking to fields of variants behind a type alias.
- Correctly resolve links to fields and variants behind a type alias to the alias's version of the docs.
- Refactor some intra-doc links code to make it simpler.
- Add tests for the status quo of linking to associated items behind aliases.

Future steps:
- Nail down the rules of when inherent and trait impls are inlined into an alias's docs, and when impls on the alias appear for the aliased type.
- Adjust the resolutions of intra-doc links, through aliases, to associated items based on these rules.

r? @GuillaumeGomez
rust-bors bot pushed a commit that referenced this pull request Jan 14, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #150585 (Add a context-consistency check before emitting redundant generic-argument suggestions)
 - #150586 (rustdoc: Fix intra-doc link bugs involving type aliases and associated items)
 - #150590 (Don't try to recover keyword as non-keyword identifier )
 - #150817 (cleanup: remove borrowck handling for inline const patterns)
 - #150939 (resolve: Relax some asserts in glob overwriting and add tests)
 - #150966 (rustc_target: Remove unused Arch::PowerPC64LE)
 - #150971 (Disallow eii in statement position)
 - #151016 (fix: WASI threading regression by disabling pthread usage)
 - #151046 (compiler: Make Externally Implementable Item (eii) macros "semiopaque")
 - #151103 (mir_build: Simplify length-determination and indexing for array/slice patterns)
 - #151117 (Avoid serde dependency in build_helper when not necessary)
 - #151127 (Delete `MetaItemOrLitParser::Err`)

r? @ghost
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 14, 2026
…Gomez

rustdoc: Fix intra-doc link bugs involving type aliases and associated items

This PR:
- Add support for linking to fields of variants behind a type alias.
- Correctly resolve links to fields and variants behind a type alias to the alias's version of the docs.
- Refactor some intra-doc links code to make it simpler.
- Add tests for the status quo of linking to associated items behind aliases.

Future steps:
- Nail down the rules of when inherent and trait impls are inlined into an alias's docs, and when impls on the alias appear for the aliased type.
- Adjust the resolutions of intra-doc links, through aliases, to associated items based on these rules.

r? @GuillaumeGomez
rust-bors bot pushed a commit that referenced this pull request Jan 14, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #150585 (Add a context-consistency check before emitting redundant generic-argument suggestions)
 - #150586 (rustdoc: Fix intra-doc link bugs involving type aliases and associated items)
 - #150590 (Don't try to recover keyword as non-keyword identifier )
 - #150817 (cleanup: remove borrowck handling for inline const patterns)
 - #150939 (resolve: Relax some asserts in glob overwriting and add tests)
 - #150962 (Remove `FeedConstTy` and provide ty when lowering const arg)
 - #150966 (rustc_target: Remove unused Arch::PowerPC64LE)
 - #150971 (Disallow eii in statement position)
 - #151016 (fix: WASI threading regression by disabling pthread usage)
 - #151046 (compiler: Make Externally Implementable Item (eii) macros "semiopaque")
 - #151099 (Recover parse gracefully from `<const N>`)
 - #151117 (Avoid serde dependency in build_helper when not necessary)
 - #151127 (Delete `MetaItemOrLitParser::Err`)
 - #151128 (Add temporary new bors e-mail address to the mailmap)
 - #151130 (resolve: Downgrade `ambiguous_glob_imports` to warn-by-default)
 - #151138 (Rename `rust.use-lld` to `rust.bootstrap-override-lld` in INSTALL.md)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 14, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #150585 (Add a context-consistency check before emitting redundant generic-argument suggestions)
 - #150586 (rustdoc: Fix intra-doc link bugs involving type aliases and associated items)
 - #150590 (Don't try to recover keyword as non-keyword identifier )
 - #150817 (cleanup: remove borrowck handling for inline const patterns)
 - #150939 (resolve: Relax some asserts in glob overwriting and add tests)
 - #150962 (Remove `FeedConstTy` and provide ty when lowering const arg)
 - #150966 (rustc_target: Remove unused Arch::PowerPC64LE)
 - #150971 (Disallow eii in statement position)
 - #151016 (fix: WASI threading regression by disabling pthread usage)
 - #151046 (compiler: Make Externally Implementable Item (eii) macros "semiopaque")
 - #151099 (Recover parse gracefully from `<const N>`)
 - #151117 (Avoid serde dependency in build_helper when not necessary)
 - #151127 (Delete `MetaItemOrLitParser::Err`)
 - #151128 (Add temporary new bors e-mail address to the mailmap)
 - #151138 (Rename `rust.use-lld` to `rust.bootstrap-override-lld` in INSTALL.md)

r? @ghost
@rust-bors rust-bors bot merged commit e04af73 into rust-lang:main Jan 15, 2026
12 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 15, 2026
rust-timer added a commit that referenced this pull request Jan 15, 2026
Rollup merge of #150586 - intra-doc-assoc-alias, r=GuillaumeGomez

rustdoc: Fix intra-doc link bugs involving type aliases and associated items

This PR:
- Add support for linking to fields of variants behind a type alias.
- Correctly resolve links to fields and variants behind a type alias to the alias's version of the docs.
- Refactor some intra-doc links code to make it simpler.
- Add tests for the status quo of linking to associated items behind aliases.

Future steps:
- Nail down the rules of when inherent and trait impls are inlined into an alias's docs, and when impls on the alias appear for the aliased type.
- Adjust the resolutions of intra-doc links, through aliases, to associated items based on these rules.

r? @GuillaumeGomez
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 15, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#150585 (Add a context-consistency check before emitting redundant generic-argument suggestions)
 - rust-lang/rust#150586 (rustdoc: Fix intra-doc link bugs involving type aliases and associated items)
 - rust-lang/rust#150590 (Don't try to recover keyword as non-keyword identifier )
 - rust-lang/rust#150817 (cleanup: remove borrowck handling for inline const patterns)
 - rust-lang/rust#150939 (resolve: Relax some asserts in glob overwriting and add tests)
 - rust-lang/rust#150962 (Remove `FeedConstTy` and provide ty when lowering const arg)
 - rust-lang/rust#150966 (rustc_target: Remove unused Arch::PowerPC64LE)
 - rust-lang/rust#150971 (Disallow eii in statement position)
 - rust-lang/rust#151016 (fix: WASI threading regression by disabling pthread usage)
 - rust-lang/rust#151046 (compiler: Make Externally Implementable Item (eii) macros "semiopaque")
 - rust-lang/rust#151099 (Recover parse gracefully from `<const N>`)
 - rust-lang/rust#151117 (Avoid serde dependency in build_helper when not necessary)
 - rust-lang/rust#151127 (Delete `MetaItemOrLitParser::Err`)
 - rust-lang/rust#151128 (Add temporary new bors e-mail address to the mailmap)
 - rust-lang/rust#151138 (Rename `rust.use-lld` to `rust.bootstrap-override-lld` in INSTALL.md)

r? @ghost
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.

6 participants