Skip to content

Commit 101ef2b

Browse files
Correctly link to associated trait items in reexports
1 parent d682af8 commit 101ef2b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/librustdoc/html/format.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,23 @@ fn print_higher_ranked_params_with_space(
838838
pub(crate) fn print_anchor(did: DefId, text: Symbol, cx: &Context<'_>) -> impl Display {
839839
fmt::from_fn(move |f| {
840840
if let Ok(HrefInfo { url, kind, rust_path }) = href(did, cx) {
841+
let tcx = cx.tcx();
842+
let def_kind = tcx.def_kind(did);
843+
let anchor = if matches!(
844+
def_kind,
845+
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant
846+
) {
847+
let parent_def_id = tcx.parent(did);
848+
let item_type =
849+
ItemType::from_def_kind(def_kind, Some(tcx.def_kind(parent_def_id)));
850+
format!("#{}.{}", item_type.as_str(), tcx.item_name(did))
851+
} else {
852+
String::new()
853+
};
854+
841855
write!(
842856
f,
843-
r#"<a class="{kind}" href="{url}" title="{kind} {path}">{text}</a>"#,
857+
r#"<a class="{kind}" href="{url}{anchor}" title="{kind} {path}">{text}</a>"#,
844858
path = join_path_syms(rust_path),
845859
text = EscapeBodyText(text.as_str()),
846860
)

0 commit comments

Comments
 (0)