From 1bd8183c1581bffb688e07113bd2a7ee494bf2fb Mon Sep 17 00:00:00 2001 From: mitaa Date: Thu, 24 Mar 2016 06:16:23 +0100 Subject: [PATCH] Don't hardcode item-type anchor ids These should always correspond to the values in `ItemType::to_static_str` --- src/librustdoc/html/render.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 51e069c6668..24b84212a89 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2160,8 +2160,9 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "

Fields

\n")?; for field in fields { write!(w, " -
\ + \ {name}", + shortty = ItemType::StructField, stab = field.stability_class(), name = field.name.as_ref().unwrap())?; document(w, cx, field)?; @@ -2231,7 +2232,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, if !e.variants.is_empty() { write!(w, "

Variants

\n")?; for variant in &e.variants { - write!(w, "
{name}", + write!(w, "
{name}", + shortty = ItemType::Variant, name = variant.name.as_ref().unwrap())?; document(w, cx, variant)?; @@ -2247,8 +2249,9 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, ")?; for field in fields { write!(w, "
\ + id='{shortty}.{v}.field.{f}'>\ {f}", + shortty = ItemType::Variant, v = variant.name.as_ref().unwrap(), f = field.name.as_ref().unwrap())?; document(w, cx, field)?; @@ -2460,6 +2463,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item, link: AssocItemLink, render_static: bool, outer_version: Option<&str>) -> fmt::Result { + let shortty = shortty(item); let name = item.name.as_ref().unwrap(); let is_static = match item.inner { @@ -2472,8 +2476,8 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi clean::MethodItem(..) | clean::TyMethodItem(..) => { // Only render when the method is not static or we allow static methods if !is_static || render_static { - let id = derive_id(format!("method.{}", name)); - write!(w, "

", id, shortty(item))?; + let id = derive_id(format!("{}.{}", shortty, name)); + write!(w, "

", id, shortty)?; render_stability_since_raw(w, item.stable_since(), outer_version)?; write!(w, "")?; render_assoc_item(w, item, link)?; @@ -2481,26 +2485,26 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } } clean::TypedefItem(ref tydef, _) => { - let id = derive_id(format!("associatedtype.{}", name)); - write!(w, "

", id, shortty(item))?; + let id = derive_id(format!("{}.{}", ItemType::AssociatedType, name)); + write!(w, "

", id, shortty)?; write!(w, "type {} = {}", name, tydef.type_)?; write!(w, "

\n")?; } clean::AssociatedConstItem(ref ty, ref default) => { - let id = derive_id(format!("associatedconstant.{}", name)); - write!(w, "

", id, shortty(item))?; + let id = derive_id(format!("{}.{}", shortty, name)); + write!(w, "

", id, shortty)?; assoc_const(w, item, ty, default.as_ref())?; write!(w, "

\n")?; } clean::ConstantItem(ref c) => { - let id = derive_id(format!("associatedconstant.{}", name)); - write!(w, "

", id, shortty(item))?; + let id = derive_id(format!("{}.{}", shortty, name)); + write!(w, "

", id, shortty)?; assoc_const(w, item, &c.type_, Some(&c.expr))?; write!(w, "

\n")?; } clean::AssociatedTypeItem(ref bounds, ref default) => { - let id = derive_id(format!("associatedtype.{}", name)); - write!(w, "

", id, shortty(item))?; + let id = derive_id(format!("{}.{}", shortty, name)); + write!(w, "

", id, shortty)?; assoc_type(w, item, bounds, default)?; write!(w, "

\n")?; }