Skip to content

Fix jump-to-def links broken by turbofish syntax#156727

Open
abdul2801 wants to merge 2 commits into
rust-lang:mainfrom
abdul2801:docs
Open

Fix jump-to-def links broken by turbofish syntax#156727
abdul2801 wants to merge 2 commits into
rust-lang:mainfrom
abdul2801:docs

Conversation

@abdul2801
Copy link
Copy Markdown

@abdul2801 abdul2801 commented May 18, 2026

Fixes #156706

@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 May 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 18, 2026

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
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, fmease, lolbinarycat, notriddle

@rust-log-analyzer

This comment has been minimized.


pub fn foo() {
// `PhantomData::<usize>` — `PhantomData` must be linked despite the turbofish.
//@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'PhantomData'
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez May 18, 2026

Choose a reason for hiding this comment

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

The type appears 3 times, so the test is not really checking much. Use a type alias instead for the specific one that you need to be tested. For example:

type TheOne = PhantomData;

let _: TheOne::<usize> = PhantomData;

The idea is to make TheOne appears only once. Then you can check like you did with //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne'.

View changes since the review

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.

An alternative would be to use count but I think it'd be less robust (and readable).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Switched to checking the local reference link since a type alias links to its own
definition rather than to struct.PhantomData.html.

Copy link
Copy Markdown
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.

Fix looks good, please just fix the test and squash your commits once done.

View changes since this review

@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 May 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 18, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@fmease
Copy link
Copy Markdown
Member

fmease commented May 18, 2026

You've linked to the wrong issue (#156707). I've updated the PR description to make it reference #156706 instead.

@rust-log-analyzer

This comment has been minimized.

Handle turbofish syntax correctly in rustdoc jump-to-def links
and add regression tests covering type aliases.
// `PhantomData::<usize>` — `PhantomData` must be linked despite the turbofish.
type TheOne = PhantomData<()>;

//@ has - '//a[@href="#13"]' 'TheOne'
Copy link
Copy Markdown
Member

@GuillaumeGomez GuillaumeGomez May 19, 2026

Choose a reason for hiding this comment

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

That doesn't fix anything. ^^'

View changes since the review

Copy link
Copy Markdown
Author

@abdul2801 abdul2801 May 19, 2026

Choose a reason for hiding this comment

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

Is using an import alias fine

use std::marker::PhantomData as TheOne;

pub fn foo() {
    //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne'
    let _: TheOne::<usize>;
}

cuz the idea you mentioned

use std::marker::PhantomData;

type TheOne = PhantomData<()>;

pub fn foo() {
    //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne'
    let _: TheOne::<usize> = PhantomData;
}

it ends up genenrating this html

<a href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html">std::marker::PhantomData</a>
'<a href="../../foo/fn.foo.html">foo</a>'
'<a href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html">PhantomData</a>'
'<a href="#13">TheOne</a>'
'<a href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>'
'<a href="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html">PhantomData</a>'`

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.

Ah yes, much better. An aliased import is much better!

@GuillaumeGomez
Copy link
Copy Markdown
Member

Thanks!

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 19, 2026

📌 Commit afedb87 has been approved by GuillaumeGomez

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 10. This pull request will be tested once the tree is reopened.

@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 May 19, 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 fails to linkify paths containing turbofish on source code pages under --generate-link-to-definition

6 participants