Skip to content

rustdoc: Don't add extra newlines for fully opaque structs #35667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 {}