Skip to content

Commit

Permalink
rustdoc: Don't add extra newlines for fully opaque structs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ollie27 committed Sep 9, 2016
1 parent ea45edf commit 8154a6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/librustdoc/html/render.rs
Expand Up @@ -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, "}}")?;
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc/structfields.rs
Expand Up @@ -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 {}

0 comments on commit 8154a6b

Please sign in to comment.