From: Oliver Middleton Date: Sun, 14 Aug 2016 17:01:25 +0000 (+0100) Subject: rustdoc: Don't add extra newlines for fully opaque structs X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8154a6bc69b42813ffda91adcefd9f277338acf3;p=rust.git rustdoc: Don't add extra newlines for fully opaque structs Changes the definition for opaque structs to look like `pub struct Vec { /* fields omitted */ }` to save space on the page. Also only use one line for empty braced structs. --- diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2be6177ea34..d01a5e312a3 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2509,19 +2509,28 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, if let Some(g) = g { write!(w, "{}", WhereClause(g))? } - write!(w, " {{\n{}", tab)?; + let mut has_visible_fields = false; + write!(w, " {{")?; for field in fields { if let clean::StructFieldItem(ref ty) = field.inner { - write!(w, " {}{}: {},\n{}", + write!(w, "\n{} {}{}: {},", + tab, VisSpace(&field.visibility), field.name.as_ref().unwrap(), - *ty, - tab)?; + *ty)?; + has_visible_fields = true; } } - if it.has_stripped_fields().unwrap() { - write!(w, " // some fields omitted\n{}", tab)?; + if has_visible_fields { + if it.has_stripped_fields().unwrap() { + write!(w, "\n{} // some fields omitted", tab)?; + } + write!(w, "\n{}", tab)?; + } else if it.has_stripped_fields().unwrap() { + // If there are no visible fields we can just display + // `{ /* fields omitted */ }` to save space. + write!(w, " /* fields omitted */ ")?; } write!(w, "}}")?; } diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index c0bfe3ffe3c..75d9be856d7 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -48,3 +48,13 @@ pub enum Qux { // @has - //pre "// some fields omitted" }, } + +// @has structfields/struct.Baz.html //pre "pub struct Baz { /* fields omitted */ }" +pub struct Baz { + x: u8, + #[doc(hidden)] + pub y: u8, +} + +// @has structfields/struct.Quux.html //pre "pub struct Quux {}" +pub struct Quux {}