-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
rustdoc: Fix intra-doc link bugs involving type aliases and associated items #150586
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
Conversation
|
Is it ready for review? (It's a draft so wondering ^^') |
|
I'm planning to add one more commit, but it's mostly done. |
|
It's best reviewed commit-by-commit btw since I moved a lot of code around. |
|
☔ The latest upstream changes (presumably #150645) made this pull request unmergeable. Please resolve the merge conflicts. |
1 similar comment
|
☔ 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.
2bd0b56 to
844ae64
Compare
|
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. |
This comment has been minimized.
This comment has been minimized.
844ae64 to
2b618ed
Compare
| } | ||
|
|
||
| let search_for_field = || { | ||
| let (DefKind::Struct | DefKind::Union) = adt_def_kind else { return vec![] }; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please open an issue. :)
There was a problem hiding this 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.
|
@bors r=GuillaumeGomez |
…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
…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
|
Commit 2b618ed has been unapproved. |
|
A rollup failed with the same error again, so this was probably incorrectly r-'ed |
This comment has been minimized.
This comment has been minimized.
rustdoc: Fix intra-doc link bugs involving type aliases and associated items try-job: dist-x86_64-linux-alt
|
@bors r=GuillaumeGomez |
…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
…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
…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
…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
…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
…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
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
…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
This PR:
Future steps:
r? @GuillaumeGomez