Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Nov 5, 2025

Fixes #148008.

Issue was that we didn't add anchors in this case.

r? @lolbinarycat

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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 Nov 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 5, 2025

lolbinarycat is currently at their maximum review capacity.
They may take a while to respond.

@rustbot

This comment has been minimized.

Comment on lines 10 to 14
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;
}
Copy link
Contributor

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.

Comment on lines +825 to +853
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()
};
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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 😉 ).

@lolbinarycat
Copy link
Contributor

@rustbot author

@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 Nov 5, 2025
@GuillaumeGomez GuillaumeGomez force-pushed the fix-import_trait_associated_functions branch from eb703aa to b9d6b37 Compare November 5, 2025 21:31
@rustbot

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

@rustbot ready

@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 Nov 6, 2025
let def_kind = tcx.def_kind(did);
let anchor = if matches!(
def_kind,
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant
Copy link
Contributor

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...

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #148648.

@lolbinarycat
Copy link
Contributor

Another point of duplication: this is starting to look a fair bit like what collect_intra_doc_links has in UrlFragment::render.

@GuillaumeGomez
Copy link
Member Author

Yep, part of the unification we should handle too. :)

@bors
Copy link
Collaborator

bors commented Nov 9, 2025

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

@GuillaumeGomez GuillaumeGomez force-pushed the fix-import_trait_associated_functions branch from b9d6b37 to 044245c Compare November 13, 2025 15:40
@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

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.

@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@GuillaumeGomez
Copy link
Member Author

Fixed merge conflicts.

@lolbinarycat
Copy link
Contributor

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+

@bors
Copy link
Collaborator

bors commented Nov 13, 2025

📌 Commit 044245c has been approved by lolbinarycat

It is now in the queue for this repository.

@bors bors 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 Nov 13, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2025
…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`
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2025
…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``
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2025
…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```
bors added a commit that referenced this pull request Nov 14, 2025
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
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 14, 2025
…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````
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 14, 2025
…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`````
bors added a commit that referenced this pull request Nov 14, 2025
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
@bors bors merged commit 89902f4 into rust-lang:main Nov 14, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 14, 2025
@bors
Copy link
Collaborator

bors commented Nov 14, 2025

⌛ Testing commit 044245c with merge c880acd...

rust-timer added a commit that referenced this pull request Nov 14, 2025
Rollup merge of #148543 - GuillaumeGomez:fix-import_trait_associated_functions, r=lolbinarycat

Correctly link to associated trait items in reexports

Fixes #148008.

Issue was that we didn't add anchors in this case.

r? ``````@lolbinarycat``````
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 doesn't properly link used trait associated items

4 participants