From 101ef2bf81ef8715fa123bdde4d139f158efe578 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 5 Nov 2025 17:50:21 +0100 Subject: [PATCH] Correctly link to associated trait items in reexports --- src/librustdoc/html/format.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 4843c20c758e..b7f6d84ea36c 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -838,9 +838,23 @@ fn print_higher_ranked_params_with_space( pub(crate) fn print_anchor(did: DefId, text: Symbol, cx: &Context<'_>) -> impl Display { fmt::from_fn(move |f| { if let Ok(HrefInfo { url, kind, rust_path }) = href(did, cx) { + 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() + }; + write!( f, - r#"{text}"#, + r#"{text}"#, path = join_path_syms(rust_path), text = EscapeBodyText(text.as_str()), )