From c454d92f618df7e27f11bea4c38eff7d52b45f33 Mon Sep 17 00:00:00 2001 From: Abdul Rafey Ahmed Date: Tue, 19 May 2026 02:13:40 +0530 Subject: [PATCH 1/2] fix: improve turbofish jump-to-def handling Handle turbofish syntax correctly in rustdoc jump-to-def links and add regression tests covering type aliases. --- src/librustdoc/html/highlight.rs | 4 ++-- tests/rustdoc-html/jump-to-def/turbofish.rs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/rustdoc-html/jump-to-def/turbofish.rs diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 1c162a79c4c44..bf0f70f1a00be 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -1001,8 +1001,8 @@ impl<'src> Classifier<'src> { has_ident = true; nb_items += 1; } else if nb > 0 && has_ident { - // Following `;` will be handled on its own. - break Some(nb_items - 1); + // Drop all the colons we just peeked (e.g. `Option::` → keep `Option`). + break Some(nb_items - nb); } else if has_ident { break Some(nb_items); } else { diff --git a/tests/rustdoc-html/jump-to-def/turbofish.rs b/tests/rustdoc-html/jump-to-def/turbofish.rs new file mode 100644 index 0000000000000..1ad7a112a4343 --- /dev/null +++ b/tests/rustdoc-html/jump-to-def/turbofish.rs @@ -0,0 +1,17 @@ +// This test ensures that turbofish (`::<...>`) does not prevent jump-to-definition +// links from being generated. + +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/turbofish.rs.html' +use std::marker::PhantomData; + +pub fn foo() { + // `PhantomData::` — `PhantomData` must be linked despite the turbofish. + type TheOne = PhantomData<()>; + + //@ has - '//a[@href="#13"]' 'TheOne' + let _: TheOne:: = PhantomData; +} From afedb8727e5ade1e789758028bedfc427ff737e9 Mon Sep 17 00:00:00 2001 From: abdul2801 Date: Tue, 19 May 2026 19:29:13 +0530 Subject: [PATCH 2/2] Update turbofish.rs --- tests/rustdoc-html/jump-to-def/turbofish.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/rustdoc-html/jump-to-def/turbofish.rs b/tests/rustdoc-html/jump-to-def/turbofish.rs index 1ad7a112a4343..a2e8caa38bc9e 100644 --- a/tests/rustdoc-html/jump-to-def/turbofish.rs +++ b/tests/rustdoc-html/jump-to-def/turbofish.rs @@ -6,12 +6,10 @@ #![crate_name = "foo"] //@ has 'src/foo/turbofish.rs.html' -use std::marker::PhantomData; +use std::marker::PhantomData as TheOne; -pub fn foo() { - // `PhantomData::` — `PhantomData` must be linked despite the turbofish. - type TheOne = PhantomData<()>; - //@ has - '//a[@href="#13"]' 'TheOne' - let _: TheOne:: = PhantomData; +pub fn foo() { + //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'TheOne' + let _: TheOne::; }