Fix link title attribute value when field of enum variants

This commit is contained in:
Guillaume Gomez
2026-08-13 16:54:57 +02:00
parent a04c7a037d
commit a89abc8225
2 changed files with 19 additions and 2 deletions

View File

@@ -674,11 +674,15 @@ pub(crate) fn link_tooltip(
fqp
};
if let &Some(UrlFragment::Item(id)) = fragment {
write!(f, "{} ", cx.tcx().def_descr(id))?;
let tcx = cx.tcx();
write!(f, "{} ", tcx.def_descr(id))?;
for component in fqp {
write!(f, "{component}::")?;
}
write!(f, "{}", cx.tcx().item_name(id))?;
if *shortty == ItemType::Enum && tcx.def_kind(id) == DefKind::Field {
write!(f, "{}::", tcx.item_name(tcx.parent(id)))?;
}
write!(f, "{}", tcx.item_name(id))?;
} else if !fqp.is_empty() {
write!(f, "{shortty} ")?;
write!(f, "{}", join_path_syms(fqp))?;

View File

@@ -0,0 +1,13 @@
// This test ensures that the generated "title" attribute for field of enum variant
// is correctly generated and includes the variant's name.
// Regression test for <https://github.com/rust-lang/rust/issues/161028>.
#![crate_name = "foo"]
//@ has 'foo/enum.Enum.html'
//@ has - '//*[@class="docblock"]//a[@title="field foo::Enum::Variant::field"]' 'Enum::Variant::field'
/// [Enum::Variant::field]
pub enum Enum {
Variant { field: i32 }
}