Skip to content

Commit ae0e45c

Browse files
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
1 parent 36bc448 commit ae0e45c

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

Diff for: src/librustdoc/html/format.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ impl<'a> fmt::Display for WhereClause<'a> {
192192
clause.push_str(" where");
193193
} else {
194194
if end_newline {
195-
clause.push_str("<span class=\"where fmt-newline\">where");
195+
clause.push_str(" <span class=\"where fmt-newline\">where");
196196
} else {
197-
clause.push_str("<span class=\"where\">where");
197+
clause.push_str(" <span class=\"where\">where");
198198
}
199199
}
200200
for (i, pred) in gens.where_predicates.iter().enumerate() {
@@ -241,8 +241,11 @@ impl<'a> fmt::Display for WhereClause<'a> {
241241
clause.push_str("</span>");
242242
let padding = repeat("&nbsp;").take(indent + 4).collect::<String>();
243243
clause = clause.replace("<br>", &format!("<br>{}", padding));
244-
clause.insert_str(0, &repeat("&nbsp;").take(indent).collect::<String>());
245-
if !end_newline {
244+
clause.insert_str(0, &repeat("&nbsp;").take(indent.saturating_sub(1))
245+
.collect::<String>());
246+
if end_newline {
247+
clause.push(' ');
248+
} else {
246249
clause.insert_str(0, "<br>");
247250
}
248251
}

Diff for: src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2710,14 +2710,14 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
27102710
}
27112711
write!(w, ")")?;
27122712
if let Some(g) = g {
2713-
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })?
2713+
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })?
27142714
}
27152715
write!(w, ";")?;
27162716
}
27172717
doctree::Unit => {
27182718
// Needed for PhantomData.
27192719
if let Some(g) = g {
2720-
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })?
2720+
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })?
27212721
}
27222722
write!(w, ";")?;
27232723
}

Diff for: src/test/rustdoc/impl-parts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl AnOibit for .. {}
1717
pub struct Foo<T> { field: T }
1818

1919
// @has impl_parts/struct.Foo.html '//*[@class="impl"]//code' \
20-
// "impl<T: Clone> !AnOibit for Foo<T> where T: Sync"
20+
// "impl<T: Clone> !AnOibit for Foo<T> where T: Sync,"
2121
// @has impl_parts/trait.AnOibit.html '//*[@class="item-list"]//code' \
22-
// "impl<T: Clone> !AnOibit for Foo<T> where T: Sync"
22+
// "impl<T: Clone> !AnOibit for Foo<T> where T: Sync,"
2323
impl<T: Clone> !AnOibit for Foo<T> where T: Sync {}

Diff for: src/test/rustdoc/issue-20727-4.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
3535

3636
pub mod reexport {
3737
// @has issue_20727_4/reexport/trait.Index.html
38-
// @has - '//*[@class="rust trait"]' 'trait Index<Idx> where Idx: ?Sized {'
38+
// @has - '//*[@class="rust trait"]' 'trait Index<Idx> where Idx: ?Sized, {'
3939
// @has - '//*[@class="rust trait"]' 'type Output: ?Sized'
4040
// @has - '//*[@class="rust trait"]' \
4141
// 'fn index(&self, index: Idx) -> &Self::Output'
4242
pub use issue_20727::Index;
4343

4444
// @has issue_20727_4/reexport/trait.IndexMut.html
4545
// @has - '//*[@class="rust trait"]' \
46-
// 'trait IndexMut<Idx>: Index<Idx> where Idx: ?Sized {'
46+
// 'trait IndexMut<Idx>: Index<Idx> where Idx: ?Sized, {'
4747
// @has - '//*[@class="rust trait"]' \
4848
// 'fn index_mut(&mut self, index: Idx) -> &mut Self::Output;'
4949
pub use issue_20727::IndexMut;

Diff for: src/test/rustdoc/where.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ pub enum Foxtrot<F> { Foxtrot1(F) }
4444
impl<F> MyTrait for Foxtrot<F> where F: MyTrait {}
4545

4646
// @has foo/type.Golf.html '//pre[@class="rust typedef"]' \
47-
// "type Golf<T> where T: Clone = (T, T)"
47+
// "type Golf<T> where T: Clone, = (T, T)"
4848
pub type Golf<T> where T: Clone = (T, T);

0 commit comments

Comments
 (0)