From ae0e45c02808551ec27ed940fad9a05cd9bcbaed Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Thu, 6 Apr 2017 14:19:45 -0500 Subject: [PATCH] rustdoc: where clause adjustment to fix tests - add spaces to output so stripping lines and breaking spaces renders the same - add commas to where clauses in rustdoc tests to match the new output --- src/librustdoc/html/format.rs | 11 +++++++---- src/librustdoc/html/render.rs | 4 ++-- src/test/rustdoc/impl-parts.rs | 4 ++-- src/test/rustdoc/issue-20727-4.rs | 4 ++-- src/test/rustdoc/where.rs | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 7c1139d7135..13a31c55702 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -192,9 +192,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { clause.push_str(" where"); } else { if end_newline { - clause.push_str("where"); + clause.push_str(" where"); } else { - clause.push_str("where"); + clause.push_str(" where"); } } for (i, pred) in gens.where_predicates.iter().enumerate() { @@ -241,8 +241,11 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { clause.push_str(""); let padding = repeat(" ").take(indent + 4).collect::(); clause = clause.replace("
", &format!("
{}", padding)); - clause.insert_str(0, &repeat(" ").take(indent).collect::()); - if !end_newline { + clause.insert_str(0, &repeat(" ").take(indent.saturating_sub(1)) + .collect::()); + if end_newline { + clause.push(' '); + } else { clause.insert_str(0, "
"); } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b1ac6a5127f..af2beacf58a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2710,14 +2710,14 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, } write!(w, ")")?; if let Some(g) = g { - write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })? + write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })? } write!(w, ";")?; } doctree::Unit => { // Needed for PhantomData. if let Some(g) = g { - write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })? + write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })? } write!(w, ";")?; } diff --git a/src/test/rustdoc/impl-parts.rs b/src/test/rustdoc/impl-parts.rs index 89c5e60e343..48ef4b6be66 100644 --- a/src/test/rustdoc/impl-parts.rs +++ b/src/test/rustdoc/impl-parts.rs @@ -17,7 +17,7 @@ impl AnOibit for .. {} pub struct Foo { field: T } // @has impl_parts/struct.Foo.html '//*[@class="impl"]//code' \ -// "impl !AnOibit for Foo where T: Sync" +// "impl !AnOibit for Foo where T: Sync," // @has impl_parts/trait.AnOibit.html '//*[@class="item-list"]//code' \ -// "impl !AnOibit for Foo where T: Sync" +// "impl !AnOibit for Foo where T: Sync," impl !AnOibit for Foo where T: Sync {} diff --git a/src/test/rustdoc/issue-20727-4.rs b/src/test/rustdoc/issue-20727-4.rs index 9ebd1c448ee..960e40b0709 100644 --- a/src/test/rustdoc/issue-20727-4.rs +++ b/src/test/rustdoc/issue-20727-4.rs @@ -35,7 +35,7 @@ pub trait IndexMut: Index { pub mod reexport { // @has issue_20727_4/reexport/trait.Index.html - // @has - '//*[@class="rust trait"]' 'trait Index where Idx: ?Sized {' + // @has - '//*[@class="rust trait"]' 'trait Index where Idx: ?Sized, {' // @has - '//*[@class="rust trait"]' 'type Output: ?Sized' // @has - '//*[@class="rust trait"]' \ // 'fn index(&self, index: Idx) -> &Self::Output' @@ -43,7 +43,7 @@ pub mod reexport { // @has issue_20727_4/reexport/trait.IndexMut.html // @has - '//*[@class="rust trait"]' \ - // 'trait IndexMut: Index where Idx: ?Sized {' + // 'trait IndexMut: Index where Idx: ?Sized, {' // @has - '//*[@class="rust trait"]' \ // 'fn index_mut(&mut self, index: Idx) -> &mut Self::Output;' pub use issue_20727::IndexMut; diff --git a/src/test/rustdoc/where.rs b/src/test/rustdoc/where.rs index d8dc115abf9..e691f7c5bea 100644 --- a/src/test/rustdoc/where.rs +++ b/src/test/rustdoc/where.rs @@ -44,5 +44,5 @@ pub enum Foxtrot { Foxtrot1(F) } impl MyTrait for Foxtrot where F: MyTrait {} // @has foo/type.Golf.html '//pre[@class="rust typedef"]' \ -// "type Golf where T: Clone = (T, T)" +// "type Golf where T: Clone, = (T, T)" pub type Golf where T: Clone = (T, T); -- 2.44.0