From 19f1bade5fd8efb5e036ed2fadc0abd397cecb9f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Apr 2019 23:06:49 +0200 Subject: [PATCH] Fix items alignment --- src/librustdoc/html/render.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e99cdb90b0a..a2e843828f7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3389,8 +3389,10 @@ fn assoc_const(w: &mut fmt::Formatter<'_>, it: &clean::Item, ty: &clean::Type, _default: Option<&String>, - link: AssocItemLink<'_>) -> fmt::Result { - write!(w, "{}const {}: {}", + link: AssocItemLink<'_>, + extra: &str) -> fmt::Result { + write!(w, "{}{}const {}: {}", + extra, VisSpace(&it.visibility), naive_assoc_href(it, link), it.name.as_ref().unwrap(), @@ -3401,8 +3403,10 @@ fn assoc_const(w: &mut fmt::Formatter<'_>, fn assoc_type(w: &mut W, it: &clean::Item, bounds: &[clean::GenericBound], default: Option<&clean::Type>, - link: AssocItemLink<'_>) -> fmt::Result { - write!(w, "type {}", + link: AssocItemLink<'_>, + extra: &str) -> fmt::Result { + write!(w, "{}type {}", + extra, naive_assoc_href(it, link), it.name.as_ref().unwrap())?; if !bounds.is_empty() { @@ -3513,10 +3517,12 @@ fn method(w: &mut fmt::Formatter<'_>, method(w, item, m.header, &m.generics, &m.decl, link, parent) } clean::AssociatedConstItem(ref ty, ref default) => { - assoc_const(w, item, ty, default.as_ref(), link) + assoc_const(w, item, ty, default.as_ref(), link, + if parent == ItemType::Trait { " " } else { "" }) } clean::AssociatedTypeItem(ref bounds, ref default) => { - assoc_type(w, item, bounds, default.as_ref(), link) + assoc_type(w, item, bounds, default.as_ref(), link, + if parent == ItemType::Trait { " " } else { "" }) } _ => panic!("render_assoc_item called on non-associated-item") } @@ -4129,7 +4135,8 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result { out.push_str(" "); assoc_type(&mut out, it, &[], Some(&tydef.type_), - AssocItemLink::GotoSource(t_did, &FxHashSet::default()))?; + AssocItemLink::GotoSource(t_did, &FxHashSet::default()), + "")?; out.push_str(";"); } } @@ -4165,7 +4172,8 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt if let clean::TypedefItem(ref tydef, _) = it.inner { write!(w, " ")?; assoc_type(w, it, &vec![], Some(&tydef.type_), - AssocItemLink::Anchor(None))?; + AssocItemLink::Anchor(None), + "")?; write!(w, ";")?; } } @@ -4235,7 +4243,7 @@ fn doc_impl_item(w: &mut fmt::Formatter<'_>, cx: &Context, item: &clean::Item, let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

", id, item_type, extra_class)?; write!(w, "", ns_id)?; - assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?; + assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id), "")?; write!(w, "

")?; } clean::AssociatedConstItem(ref ty, ref default) => { @@ -4243,7 +4251,7 @@ fn doc_impl_item(w: &mut fmt::Formatter<'_>, cx: &Context, item: &clean::Item, let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

", id, item_type, extra_class)?; write!(w, "", ns_id)?; - assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?; + assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "")?; write!(w, "")?; render_stability_since_raw(w, item.stable_since(), outer_version)?; if let Some(l) = (Item { cx, item }).src_href() { @@ -4257,7 +4265,7 @@ fn doc_impl_item(w: &mut fmt::Formatter<'_>, cx: &Context, item: &clean::Item, let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "

", id, item_type, extra_class)?; write!(w, "", ns_id)?; - assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?; + assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "")?; write!(w, "

")?; } clean::StrippedItem(..) => return Ok(()),