-
Notifications
You must be signed in to change notification settings - Fork 14k
Correctly link to associated trait items in reexports #148543
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
base: main
Are you sure you want to change the base?
Correctly link to associated trait items in reexports #148543
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
| pub trait Test { | ||
| //@ has - '//*[@id="reexport.method"]//a[@href="trait.Test.html#tymethod.method"]' 'method' | ||
| fn method(); | ||
| //@ has - '//*[@id="reexport.CONST"]//a[@href="trait.Test.html#associatedconstant.CONST"]' 'CONST' | ||
| const CONST: u8; | ||
| //@ has - '//*[@id="reexport.Type"]//a[@href="trait.Test.html#associatedtype.Type"]' 'Type' | ||
| type Type; | ||
| } |
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.
The placement of these comments makes it look like they're looking for the items themselves, not the reexports of the items.
| let tcx = cx.tcx(); | ||
| let def_kind = tcx.def_kind(did); | ||
| let anchor = if matches!( | ||
| def_kind, | ||
| DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant | ||
| ) { | ||
| let parent_def_id = tcx.parent(did); | ||
| let item_type = | ||
| ItemType::from_def_kind(def_kind, Some(tcx.def_kind(parent_def_id))); | ||
| format!("#{}.{}", item_type.as_str(), tcx.item_name(did)) | ||
| } else { | ||
| String::new() | ||
| }; |
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.
This duplicates code already present in assoc_href_attr. Please either call that function, or factor out their common code into a shared function.
Also, I think the functions href, make_href, and href_with_root_path should have doc comments explaining that they do not include the fragment.
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.
assoc_href_attr handles things very differently and is actually calling href internally.
A better contender for merge would be collect_intra_doc_links and in particular clean::Item::links which also calls href but also handles fragments on its own.
We have three different ways to handle them and a bigger unification is required. Gonna open an issue for that but sadly, it's likely gonna involve quite some work.
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.
I opened #148547 with an explanation of what I have in mind (and what I already tried too 😉 ).
|
@rustbot author |
eb703aa to
b9d6b37
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
| let def_kind = tcx.def_kind(did); | ||
| let anchor = if matches!( | ||
| def_kind, | ||
| DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant |
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.
Do we want to add DefKind::Field here for completeness? You can't reexport a field, but this function is used in a lot of functions, who themselves are used in a lot of functions, and there's also the chance this function is used for something else in the future...
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.
Actually, Field would require it's own complexities due to enum variant fields, so maybe not...
is an assertion worth it to find the bug if it ever does happen? or is it better to emit a broken link than ICE?
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.
I kept the current behaviour to emit a wrong link. Opening an issue though.
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.
Opened #148648.
|
Another point of duplication: this is starting to look a fair bit like what collect_intra_doc_links has in |
|
Yep, part of the unification we should handle too. :) |
|
☔ The latest upstream changes (presumably #148692) made this pull request unmergeable. Please resolve the merge conflicts. |
b9d6b37 to
044245c
Compare
|
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. |
|
|
Fixed merge conflicts. |
|
I think this is about as good as we're gonna get it for now, the refactoring will likely need to be done in a followup. @bors r+ |
…sociated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes rust-lang#148008. Issue was that we didn't add anchors in this case. r? `@lolbinarycat`
…sociated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes rust-lang#148008. Issue was that we didn't add anchors in this case. r? ``@lolbinarycat``
…sociated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes rust-lang#148008. Issue was that we didn't add anchors in this case. r? ```@lolbinarycat```
Rollup of 14 pull requests Successful merges: - #146978 (Emit error when using path-segment keyword as cfg pred) - #148543 (Correctly link to associated trait items in reexports) - #148808 (Some resolve cleanups) - #148812 (coverage: Associate hole spans with expansion tree nodes ) - #148826 (CStr docs: Fix CStr vs &CStr confusion) - #148850 (Implement `Read::read_array`) - #148867 (Refactor `Box::take`) - #148870 (Remove unused LLVMModuleRef argument) - #148878 (error when ABI does not support guaranteed tail calls) - #148901 (Disable rustdoc-test-builder test partially for SGX target.) - #148902 (add missing s390x target feature to std detect test) - #148904 (waffle: stop watching codegen ssa) - #148906 (Expose fmt::Arguments::from_str as unstable.) - #148907 (add assembly test for infinite recursion with `become`) r? `@ghost` `@rustbot` modify labels: rollup
…sociated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes rust-lang#148008. Issue was that we didn't add anchors in this case. r? ````@lolbinarycat````
…sociated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes rust-lang#148008. Issue was that we didn't add anchors in this case. r? `````@lolbinarycat`````
…sociated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes rust-lang#148008. Issue was that we didn't add anchors in this case. r? ``````@lolbinarycat``````
Rollup of 15 pull requests Successful merges: - #148543 (Correctly link to associated trait items in reexports) - #148808 (Some resolve cleanups) - #148812 (coverage: Associate hole spans with expansion tree nodes ) - #148826 (CStr docs: Fix CStr vs &CStr confusion) - #148850 (Implement `Read::read_array`) - #148867 (Refactor `Box::take`) - #148870 (Remove unused LLVMModuleRef argument) - #148878 (error when ABI does not support guaranteed tail calls) - #148901 (Disable rustdoc-test-builder test partially for SGX target.) - #148902 (add missing s390x target feature to std detect test) - #148904 (waffle: stop watching codegen ssa) - #148906 (Expose fmt::Arguments::from_str as unstable.) - #148907 (add assembly test for infinite recursion with `become`) - #148928 (Move & adjust some `!`-adjacent tests) - #148929 (ignore `build-rust-analyzer` even if it's a symlink) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #148008.
Issue was that we didn't add anchors in this case.
r? @lolbinarycat