Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: Trait>(_: T::Foo) {}
6 changes: 6 additions & 0 deletions tests/rustdoc-html/hidden-trait-methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

@GuillaumeGomez GuillaumeGomez Jun 5, 2026

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.

Would likely have been better to check that there is a Foo element but not in a link. !has is very bad for DOM changes.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i can make a follow up PR on this, if you don't mind?

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.

Go ahead!

pub fn hidden_projection<T: Trait>(_: T::Foo) {}
Loading