about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-09-14 04:57:47 -0700
committerGitHub <noreply@github.com>2016-09-14 04:57:47 -0700
commit97b561a0944141a02a0cebe577c3c69e436abcf4 (patch)
tree6bd4298d50a67c2772db7e1cc4b44a870dfb31ea /src
parent739d57180fa207410b8858f8cede7b8a9ea6f01e (diff)
parent8154a6bc69b42813ffda91adcefd9f277338acf3 (diff)
downloadrust-97b561a0944141a02a0cebe577c3c69e436abcf4.tar.gz
rust-97b561a0944141a02a0cebe577c3c69e436abcf4.zip
Auto merge of #35667 - ollie27:rustdoc_opaque_structs, r=steveklabnik
rustdoc: Don't add extra newlines for fully opaque structs

Changes the definition for braced structs with only private or hidden fields to save space on the page.

Before:
```
pub struct Vec<T> {
    // some fields omitted
}
```
After:
```
pub struct Vec<T> { /* fields omitted */ }
```

This also cleans up empty braced structs.

Before:
```
pub struct Foo {
}
```
After:
```
pub struct Foo {}
```

[before](https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html) [after](https://ollie27.github.io/rust_doc_test/std/vec/struct.Vec.html)

cc #34713
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/render.rs21
-rw-r--r--src/test/rustdoc/structfields.rs10
2 files changed, 25 insertions, 6 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 6da7423edb8..f352e39071c 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -2521,19 +2521,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 {}