From 9aeb7c0bed83123af0cc4fb4805a088f4fa5b36b Mon Sep 17 00:00:00 2001 From: qaijuang <237468078+qaijuang@users.noreply.github.com> Date: Thu, 4 Jun 2026 11:37:15 -0400 Subject: [PATCH 1/2] add regression tests --- .../hidden-trait-methods-with-document-hidden-items.rs | 6 ++++++ tests/rustdoc-html/hidden-trait-methods.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/rustdoc-html/hidden-trait-methods-with-document-hidden-items.rs b/tests/rustdoc-html/hidden-trait-methods-with-document-hidden-items.rs index a290992e5fec9..dc8ff4b8d266b 100644 --- a/tests/rustdoc-html/hidden-trait-methods-with-document-hidden-items.rs +++ b/tests/rustdoc-html/hidden-trait-methods-with-document-hidden-items.rs @@ -29,3 +29,9 @@ impl Trait for S { fn f() {} fn g() {} } + +// Regression test for https://github.com/rust-lang/rust/issues/151454. +//@ has foo/fn.hidden_projection.html +//@ has - '//pre[@class="rust item-decl"]' 'T::Foo' +//@ has - '//pre[@class="rust item-decl"]//a[@href="trait.Trait.html#associatedtype.Foo"]' 'Foo' +pub fn hidden_projection(_: T::Foo) {} diff --git a/tests/rustdoc-html/hidden-trait-methods.rs b/tests/rustdoc-html/hidden-trait-methods.rs index 2c342ff28b302..0e39bd9df188f 100644 --- a/tests/rustdoc-html/hidden-trait-methods.rs +++ b/tests/rustdoc-html/hidden-trait-methods.rs @@ -27,3 +27,9 @@ impl Trait for S { fn f() {} fn g() {} } + +// Regression test for https://github.com/rust-lang/rust/issues/151454. +//@ has foo/fn.hidden_projection.html +//@ has - '//pre[@class="rust item-decl"]' 'T::Foo' +//@ !has - '//pre[@class="rust item-decl"]//a[@href="trait.Trait.html#associatedtype.Foo"]' 'Foo' +pub fn hidden_projection(_: T::Foo) {} From 8e63effb6a2d2e3a2b313979fd6d09167081d992 Mon Sep 17 00:00:00 2001 From: qaijuang <237468078+qaijuang@users.noreply.github.com> Date: Thu, 4 Jun 2026 11:51:43 -0400 Subject: [PATCH 2/2] don't link doc(hidden) associated type projections --- src/librustdoc/html/format.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index cbb5fed8c4d09..0b94d2bf1e641 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -20,8 +20,8 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::{ConstStability, StabilityLevel, StableSince}; use rustc_metadata::creader::CStore; use rustc_middle::ty::{self, TyCtxt, TypingMode}; -use rustc_span::Symbol; use rustc_span::symbol::kw; +use rustc_span::{Ident, Symbol}; use tracing::{debug, trace}; use super::url_parts_builder::UrlPartsBuilder; @@ -1109,8 +1109,23 @@ fn print_qpath_data(qpath_data: &clean::QPathData, cx: &Context<'_>) -> impl Dis Some(trait_) => href(trait_.def_id(), cx).ok(), None => self_type.def_id(cx.cache()).and_then(|did| href(did, cx).ok()), }; + let tcx = cx.tcx(); + let assoc_type_is_hidden = !cx.cache().document_hidden + && trait_.as_ref().is_some_and(|trait_| { + let trait_did = trait_.def_id(); + tcx.associated_items(trait_did) + .find_by_ident_and_kind( + tcx, + Ident::with_dummy_span(assoc.name), + ty::AssocTag::Type, + trait_did, + ) + .is_some_and(|assoc_item| tcx.is_doc_hidden(assoc_item.def_id)) + }); - if let Some(HrefInfo { url, rust_path, .. }) = parent_href { + if let Some(HrefInfo { url, rust_path, .. }) = parent_href + && !assoc_type_is_hidden + { write!( f, "