Skip to content

Commit d06f72d

Browse files
Apply the same transformation to every types
1 parent 5ac7a03 commit d06f72d

File tree

3 files changed

+65
-38
lines changed

3 files changed

+65
-38
lines changed

src/librustdoc/html/format.rs

+34-20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
9090
}
9191
}
9292

93+
impl<'a, T: fmt::Debug> fmt::Debug for CommaSep<'a, T> {
94+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95+
for (i, item) in self.0.iter().enumerate() {
96+
if i != 0 { write!(f, ", ")?; }
97+
fmt::Debug::fmt(item, f)?;
98+
}
99+
Ok(())
100+
}
101+
}
102+
93103
impl<'a> fmt::Display for TyParamBounds<'a> {
94104
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95105
let &TyParamBounds(bounds) = self;
@@ -165,7 +175,7 @@ impl<'a> fmt::Display for WhereClause<'a> {
165175
if f.alternate() {
166176
clause.push_str(" where ");
167177
} else {
168-
clause.push_str(" <span class='where fmt-newline'>where ");
178+
clause.push_str(" <span class=\"where fmt-newline\">where ");
169179
}
170180
for (i, pred) in gens.where_predicates.iter().enumerate() {
171181
if i > 0 {
@@ -449,8 +459,8 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
449459
} else {
450460
root.push_str(&seg.name);
451461
root.push_str("/");
452-
write!(w, "<a class='mod'
453-
href='{}index.html'>{}</a>::",
462+
write!(w, "<a class=\"mod\"
463+
href=\"{}index.html\">{}</a>::",
454464
root,
455465
seg.name)?;
456466
}
@@ -491,7 +501,7 @@ fn primitive_link(f: &mut fmt::Formatter,
491501
Some(&def_id) if def_id.is_local() => {
492502
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
493503
let len = if len == 0 {0} else {len - 1};
494-
write!(f, "<a class='primitive' href='{}primitive.{}.html'>",
504+
write!(f, "<a class=\"primitive\" href=\"{}primitive.{}.html\">",
495505
repeat("../").take(len).collect::<String>(),
496506
prim.to_url_str())?;
497507
needs_termination = true;
@@ -508,7 +518,7 @@ fn primitive_link(f: &mut fmt::Formatter,
508518
(.., render::Unknown) => None,
509519
};
510520
if let Some((cname, root)) = loc {
511-
write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>",
521+
write!(f, "<a class=\"primitive\" href=\"{}{}/primitive.{}.html\">",
512522
root,
513523
cname,
514524
prim.to_url_str())?;
@@ -550,7 +560,7 @@ impl<'a> fmt::Display for HRef<'a> {
550560
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
551561
match href(self.did) {
552562
Some((url, shortty, fqp)) => if !f.alternate() {
553-
write!(f, "<a class='{}' href='{}' title='{} {}'>{}</a>",
563+
write!(f, "<a class=\"{}\" href=\"{}\" title=\"{} {}\">{}</a>",
554564
shortty, url, shortty, fqp.join("::"), self.text)
555565
} else {
556566
write!(f, "{}", self.text)
@@ -599,21 +609,21 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
599609
fmt::Display::fmt(one, f)?;
600610
primitive_link(f, PrimitiveType::Tuple, ",)")
601611
}
602-
&[ref one] => write!(f, "({},)", one),
612+
&[ref one] => write!(f, "({:?},)", one),
603613
many if is_not_debug => {
604614
primitive_link(f, PrimitiveType::Tuple, "(")?;
605615
fmt::Display::fmt(&CommaSep(&many), f)?;
606616
primitive_link(f, PrimitiveType::Tuple, ")")
607617
}
608-
many => write!(f, "({})", &CommaSep(&many)),
618+
many => write!(f, "({:?})", &CommaSep(&many)),
609619
}
610620
}
611621
clean::Vector(ref t) if is_not_debug => {
612622
primitive_link(f, PrimitiveType::Slice, &format!("["))?;
613623
fmt::Display::fmt(t, f)?;
614624
primitive_link(f, PrimitiveType::Slice, &format!("]"))
615625
}
616-
clean::Vector(ref t) => write!(f, "[{}]", t),
626+
clean::Vector(ref t) => write!(f, "[{:?}]", t),
617627
clean::FixedVector(ref t, ref s) if is_not_debug => {
618628
primitive_link(f, PrimitiveType::Array, "[")?;
619629
fmt::Display::fmt(t, f)?;
@@ -627,9 +637,9 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
627637
}
628638
clean::FixedVector(ref t, ref s) => {
629639
if f.alternate() {
630-
write!(f, "[{}; {}]", t, s)
640+
write!(f, "[{:?}; {}]", t, s)
631641
} else {
632-
write!(f, "[{}; {}]", t, Escape(s))
642+
write!(f, "[{:?}; {}]", t, Escape(s))
633643
}
634644
}
635645
clean::Never => f.write_str("!"),
@@ -646,9 +656,9 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
646656
}
647657
clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
648658
if f.alternate() {
649-
write!(f, "*{}{:#}", RawMutableSpace(m), t)
659+
write!(f, "*{}{:#?}", RawMutableSpace(m), t)
650660
} else {
651-
write!(f, "*{}{}", RawMutableSpace(m), t)
661+
write!(f, "*{}{:?}", RawMutableSpace(m), t)
652662
}
653663
}
654664
_ if is_not_debug => {
@@ -657,7 +667,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
657667
fmt::Display::fmt(t, f)
658668
}
659669
_ => {
660-
write!(f, "*{}{}", RawMutableSpace(m), t)
670+
write!(f, "*{}{:?}", RawMutableSpace(m), t)
661671
}
662672
}
663673
}
@@ -681,9 +691,9 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
681691
}
682692
clean::Generic(_) => {
683693
if f.alternate() {
684-
write!(f, "&{}{}[{:#}]", lt, m, **bt)
694+
write!(f, "&{}{}[{:#?}]", lt, m, **bt)
685695
} else {
686-
write!(f, "&{}{}[{}]", lt, m, **bt)
696+
write!(f, "&{}{}[{:?}]", lt, m, **bt)
687697
}
688698
}
689699
_ if is_not_debug => {
@@ -700,9 +710,9 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
700710
}
701711
_ => {
702712
if f.alternate() {
703-
write!(f, "&{}{}[{:#}]", lt, m, **bt)
713+
write!(f, "&{}{}[{:#?}]", lt, m, **bt)
704714
} else {
705-
write!(f, "&{}{}[{}]", lt, m, **bt)
715+
write!(f, "&{}{}[{:?}]", lt, m, **bt)
706716
}
707717
}
708718
}
@@ -765,12 +775,16 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool,
765775
}
766776
clean::QPath { ref name, ref self_type, ref trait_ } => {
767777
if f.alternate() {
768-
write!(f, "<{:#} as {:#}>::{}", self_type, trait_, name)
778+
if is_not_debug {
779+
write!(f, "<{:#} as {:#}>::{}", self_type, trait_, name)
780+
} else {
781+
write!(f, "<{:#?} as {:#?}>::{}", self_type, trait_, name)
782+
}
769783
} else {
770784
if is_not_debug {
771785
write!(f, "&lt;{} as {}&gt;::{}", self_type, trait_, name)
772786
} else {
773-
write!(f, "<{} as {}>::{}", self_type, trait_, name)
787+
write!(f, "<{:?} as {:?}>::{}", self_type, trait_, name)
774788
}
775789
}
776790
}

src/librustdoc/html/highlight.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ impl<U: Write> Writer for U {
144144
-> io::Result<()> {
145145
match klass {
146146
Class::None => write!(self, "{}", text),
147-
klass => write!(self, "<span class='{}'>{}</span>", klass.rustdoc_class(), text),
147+
klass => write!(self, "<span class=\"{}\">{}</span>", klass.rustdoc_class(), text),
148148
}
149149
}
150150

151151
fn enter_span(&mut self, klass: Class) -> io::Result<()> {
152-
write!(self, "<span class='{}'>", klass.rustdoc_class())
152+
write!(self, "<span class=\"{}\">", klass.rustdoc_class())
153153
}
154154

155155
fn exit_span(&mut self) -> io::Result<()> {
@@ -363,7 +363,7 @@ fn write_header(class: Option<&str>,
363363
if let Some(id) = id {
364364
write!(out, "id='{}' ", id)?;
365365
}
366-
write!(out, "class='rust {}'>\n", class.unwrap_or(""))
366+
write!(out, "class=\"rust {}\">\n", class.unwrap_or(""))
367367
}
368368

369369
fn write_footer(out: &mut Write) -> io::Result<()> {

src/librustdoc/html/render.rs

+28-15
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ impl<'a> fmt::Display for Item<'a> {
15471547
component)?;
15481548
}
15491549
}
1550-
write!(fmt, "<a class='{}' href=''>{}</a>",
1550+
write!(fmt, "<a class=\"{}\" href=''>{}</a>",
15511551
self.item.type_(), self.item.name.as_ref().unwrap())?;
15521552

15531553
write!(fmt, "</span>")?; // in-band
@@ -1667,8 +1667,20 @@ fn md_render_assoc_item(item: &clean::Item) -> String {
16671667
}
16681668
}
16691669

1670+
fn get_doc_value(item: &clean::Item) -> Option<&str> {
1671+
let x = item.doc_value();
1672+
if x.is_none() {
1673+
match item.inner {
1674+
clean::AssociatedConstItem(_, _) => Some(""),
1675+
_ => None,
1676+
}
1677+
} else {
1678+
x
1679+
}
1680+
}
1681+
16701682
fn document_full(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
1671-
if let Some(s) = item.doc_value() {
1683+
if let Some(s) = get_doc_value(item) {
16721684
write!(w, "<div class='docblock'>{}</div>",
16731685
Markdown(&format!("{}{}", md_render_assoc_item(item), s)))?;
16741686
}
@@ -1831,7 +1843,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
18311843
let doc_value = myitem.doc_value().unwrap_or("");
18321844
write!(w, "
18331845
<tr class='{stab} module-item'>
1834-
<td><a class='{class}' href='{href}'
1846+
<td><a class=\"{class}\" href=\"{href}\"
18351847
title='{title_type} {title}'>{name}</a>{unsafety_flag}</td>
18361848
<td class='docblock-short'>
18371849
{stab_docs} {docs}
@@ -2228,20 +2240,21 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink) -> String {
22282240

22292241
fn assoc_const(w: &mut fmt::Formatter,
22302242
it: &clean::Item,
2231-
_ty: &clean::Type,
2243+
ty: &clean::Type,
22322244
_default: Option<&String>,
22332245
link: AssocItemLink) -> fmt::Result {
2234-
write!(w, "const <a href='{}' class='constant'><b>{}</b></a>",
2246+
write!(w, "const <a href='{}' class=\"constant\"><b>{}</b></a>: {}",
22352247
naive_assoc_href(it, link),
2236-
it.name.as_ref().unwrap())?;
2248+
it.name.as_ref().unwrap(),
2249+
ty)?;
22372250
Ok(())
22382251
}
22392252

22402253
fn assoc_type(w: &mut fmt::Formatter, it: &clean::Item,
22412254
bounds: &Vec<clean::TyParamBound>,
22422255
default: Option<&clean::Type>,
22432256
link: AssocItemLink) -> fmt::Result {
2244-
write!(w, "type <a href='{}' class='type'>{}</a>",
2257+
write!(w, "type <a href='{}' class=\"type\">{}</a>",
22452258
naive_assoc_href(it, link),
22462259
it.name.as_ref().unwrap())?;
22472260
if !bounds.is_empty() {
@@ -2384,7 +2397,7 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23842397
let ns_id = derive_id(format!("{}.{}",
23852398
field.name.as_ref().unwrap(),
23862399
ItemType::StructField.name_space()));
2387-
write!(w, "<span id='{id}' class='{item_type}'>
2400+
write!(w, "<span id='{id}' class=\"{item_type}\">
23882401
<span id='{ns_id}' class='invisible'>
23892402
<code>{name}: {ty}</code>
23902403
</span></span>",
@@ -2426,7 +2439,7 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24262439
if fields.peek().is_some() {
24272440
write!(w, "<h2 class='fields'>Fields</h2>")?;
24282441
for (field, ty) in fields {
2429-
write!(w, "<span id='{shortty}.{name}' class='{shortty}'><code>{name}: {ty}</code>
2442+
write!(w, "<span id='{shortty}.{name}' class=\"{shortty}\"><code>{name}: {ty}</code>
24302443
</span>",
24312444
shortty = ItemType::StructField,
24322445
name = field.name.as_ref().unwrap(),
@@ -2911,7 +2924,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
29112924
if render_method_item {
29122925
let id = derive_id(format!("{}.{}", item_type, name));
29132926
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
2914-
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2927+
write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
29152928
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
29162929
write!(w, "<code>")?;
29172930
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
@@ -2923,31 +2936,31 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
29232936
clean::TypedefItem(ref tydef, _) => {
29242937
let id = derive_id(format!("{}.{}", ItemType::AssociatedType, name));
29252938
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
2926-
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2939+
write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
29272940
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
29282941
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?;
29292942
write!(w, "</code></span></h4>\n")?;
29302943
}
29312944
clean::AssociatedConstItem(ref ty, ref default) => {
29322945
let id = derive_id(format!("{}.{}", item_type, name));
29332946
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
2934-
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2947+
write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
29352948
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
29362949
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
29372950
write!(w, "</code></span></h4>\n")?;
29382951
}
29392952
clean::ConstantItem(ref c) => {
29402953
let id = derive_id(format!("{}.{}", item_type, name));
29412954
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
2942-
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2955+
write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
29432956
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
29442957
assoc_const(w, item, &c.type_, Some(&c.expr), link.anchor(&id))?;
29452958
write!(w, "</code></span></h4>\n")?;
29462959
}
29472960
clean::AssociatedTypeItem(ref bounds, ref default) => {
29482961
let id = derive_id(format!("{}.{}", item_type, name));
29492962
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
2950-
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2963+
write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?;
29512964
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
29522965
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?;
29532966
write!(w, "</code></span></h4>\n")?;
@@ -2965,7 +2978,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
29652978
// We need the stability of the item from the trait
29662979
// because impls can't have a stability.
29672980
document_stability(w, cx, it)?;
2968-
if item.doc_value().is_some() {
2981+
if get_doc_value(item).is_some() {
29692982
document_full(w, item)?;
29702983
} else {
29712984
// In case the item isn't documented,

0 commit comments

Comments
 (0)