]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Don't add extra newlines for fully opaque structs
authorOliver Middleton <olliemail27@gmail.com>
Sun, 14 Aug 2016 17:01:25 +0000 (18:01 +0100)
committerOliver Middleton <olliemail27@gmail.com>
Fri, 9 Sep 2016 00:41:42 +0000 (01:41 +0100)
Changes the definition for opaque structs to look like `pub struct Vec<T>
{ /* fields omitted */ }` to save space on the page.

Also only use one line for empty braced structs.

src/librustdoc/html/render.rs
src/test/rustdoc/structfields.rs

index 2be6177ea344ec1a499275c22135710153308bba..d01a5e312a3a27d4928bf8d88a98f0f8e995bb57 100644 (file)
@@ -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, "}}")?;
         }
index c0bfe3ffe3cf9ee576832eb096b878b0351bd47f..75d9be856d74cc477f39eee65a93f1fd6cae316b 100644 (file)
@@ -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 {}