diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 751ed7d443d290bc04652de2c7c783a7999cb79e..215d3d1a8279c6375cdebc732c5160e211a8c260 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1475,7 +1475,7 @@ pub struct PolyTrait { /// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original /// type out of the AST/TyCtxt given one of these, if more information is needed. Most importantly /// it does not preserve mutability or boxes. -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)] +#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum Type { /// structs/enums/traits (most that'd be an hir::TyPath) ResolvedPath { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 6f8c6aa7094dde3b994234642e18748885f4bb73..c796f0b20d3bb840a51b6cbff77984dd63cf097c 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -560,7 +560,8 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } } -fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt::Result { +fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, + is_not_debug: bool) -> fmt::Result { match *t { clean::Generic(ref name) => { f.write_str(name) @@ -571,7 +572,8 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: tybounds(f, typarams) } clean::Infer => write!(f, "_"), - clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()), + clean::Primitive(prim) if is_not_debug => primitive_link(f, prim, prim.as_str()), + clean::Primitive(prim) => write!(f, "{}", prim.as_str()), clean::BareFunction(ref decl) => { if f.alternate() { write!(f, "{}{}fn{:#}{:#}", @@ -589,26 +591,30 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } clean::Tuple(ref typs) => { match &typs[..] { - &[] => primitive_link(f, PrimitiveType::Tuple, "()"), - &[ref one] => { + &[] if is_not_debug => primitive_link(f, PrimitiveType::Tuple, "()"), + &[] => write!(f, "()"), + &[ref one] if is_not_debug => { primitive_link(f, PrimitiveType::Tuple, "(")?; //carry f.alternate() into this display w/o branching manually fmt::Display::fmt(one, f)?; primitive_link(f, PrimitiveType::Tuple, ",)") } - many => { + &[ref one] => write!(f, "({},)", one), + many if is_not_debug => { primitive_link(f, PrimitiveType::Tuple, "(")?; fmt::Display::fmt(&CommaSep(&many), f)?; primitive_link(f, PrimitiveType::Tuple, ")") } + many => write!(f, "({})", &CommaSep(&many)), } } - clean::Vector(ref t) => { + clean::Vector(ref t) if is_not_debug => { primitive_link(f, PrimitiveType::Slice, &format!("["))?; fmt::Display::fmt(t, f)?; primitive_link(f, PrimitiveType::Slice, &format!("]")) } - clean::FixedVector(ref t, ref s) => { + clean::Vector(ref t) => write!(f, "[{}]", t), + clean::FixedVector(ref t, ref s) if is_not_debug => { primitive_link(f, PrimitiveType::Array, "[")?; fmt::Display::fmt(t, f)?; if f.alternate() { @@ -619,10 +625,17 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: &format!("; {}]", Escape(s))) } } + clean::FixedVector(ref t, ref s) => { + if f.alternate() { + write!(f, "[{}; {}]", t, s) + } else { + write!(f, "[{}; {}]", t, Escape(s)) + } + } clean::Never => f.write_str("!"), clean::RawPointer(m, ref t) => { match **t { - clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => { + clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} if is_not_debug => { if f.alternate() { primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{}{:#}", RawMutableSpace(m), t)) @@ -631,11 +644,21 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: &format!("*{}{}", RawMutableSpace(m), t)) } } - _ => { + clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => { + if f.alternate() { + write!(f, "*{}{:#}", RawMutableSpace(m), t) + } else { + write!(f, "*{}{}", RawMutableSpace(m), t) + } + } + _ if is_not_debug => { primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{}", RawMutableSpace(m)))?; fmt::Display::fmt(t, f) } + _ => { + write!(f, "*{}{}", RawMutableSpace(m), t) + } } } clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => { @@ -647,15 +670,23 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: match **ty { clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T] match **bt { - clean::Generic(_) => + clean::Generic(_) if is_not_debug => { if f.alternate() { primitive_link(f, PrimitiveType::Slice, &format!("&{}{}[{:#}]", lt, m, **bt)) } else { primitive_link(f, PrimitiveType::Slice, &format!("&{}{}[{}]", lt, m, **bt)) - }, - _ => { + } + } + clean::Generic(_) => { + if f.alternate() { + write!(f, "&{}{}[{:#}]", lt, m, **bt) + } else { + write!(f, "&{}{}[{}]", lt, m, **bt) + } + } + _ if is_not_debug => { if f.alternate() { primitive_link(f, PrimitiveType::Slice, &format!("&{}{}[", lt, m))?; @@ -667,15 +698,26 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } primitive_link(f, PrimitiveType::Slice, "]") } + _ => { + if f.alternate() { + write!(f, "&{}{}[{:#}]", lt, m, **bt) + } else { + write!(f, "&{}{}[{}]", lt, m, **bt) + } + } } } _ => { if f.alternate() { write!(f, "&{}{}", lt, m)?; - fmt_type(&ty, f, use_absolute) + fmt_type(&ty, f, use_absolute, is_not_debug) } else { - write!(f, "&{}{}", lt, m)?; - fmt_type(&ty, f, use_absolute) + if is_not_debug { + write!(f, "&{}{}", lt, m)?; + } else { + write!(f, "&{}{}", lt, m)?; + } + fmt_type(&ty, f, use_absolute, is_not_debug) } } } @@ -725,7 +767,11 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: if f.alternate() { write!(f, "<{:#} as {:#}>::{}", self_type, trait_, name) } else { - write!(f, "<{} as {}>::{}", self_type, trait_, name) + if is_not_debug { + write!(f, "<{} as {}>::{}", self_type, trait_, name) + } else { + write!(f, "<{} as {}>::{}", self_type, trait_, name) + } } } clean::Unique(..) => { @@ -736,7 +782,13 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: impl fmt::Display for clean::Type { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt_type(self, f, false) + fmt_type(self, f, false, true) + } +} + +impl fmt::Debug for clean::Type { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt_type(self, f, false, false) } } @@ -777,7 +829,7 @@ fn fmt_impl(i: &clean::Impl, plain.push_str(" for "); } - fmt_type(&i.for_, f, use_absolute)?; + fmt_type(&i.for_, f, use_absolute, true)?; plain.push_str(&format!("{:#}", i.for_)); fmt::Display::fmt(&WhereClause(&i.generics, plain.len() + 1), f)?; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 86b7c9736dab46403818aab59ae2e0ea8a055ee4..30127ca96a15d8718c94919b54e9a252ee3f7217 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1654,9 +1654,23 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin Ok(()) } +fn md_render_assoc_item(item: &clean::Item) -> String { + match item.inner { + clean::AssociatedConstItem(ref ty, ref default) => { + if let Some(default) = default.as_ref() { + format!("```\n{}: {:?} = {}\n```\n\n", item.name.as_ref().unwrap(), ty, default) + } else { + format!("```\n{}: {:?}\n```\n\n", item.name.as_ref().unwrap(), ty) + } + } + _ => String::new(), + } +} + fn document_full(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result { if let Some(s) = item.doc_value() { - write!(w, "