Skip to content

Commit

Permalink
Remove extra space before a where clause in the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Apr 8, 2022
1 parent dc1f829 commit f6c7f10
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ crate fn print_where_clause<'a, 'tcx: 'a>(
clause = clause.replace("<br>", &format!("<br>{}", padding));
clause.insert_str(0, &"&nbsp;".repeat(indent.saturating_sub(1)));
if !end_newline {
clause.insert_str(0, "<br>");
// we insert the <br> after a single space but before multiple spaces at the start
clause.insert_str(if indent == 0 { 1 } else { 0 }, "<br>");
}
}
write!(f, "{}", clause)
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc/where.SWhere_Simd_item-decl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="docblock item-decl"><pre class="rust struct"><code>pub struct Simd&lt;T, const LANES:&#160;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>&gt;(_) <br /><span class="where">where<br />&#160;&#160;&#160;&#160;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>;</code></pre></div>
3 changes: 3 additions & 0 deletions src/test/rustdoc/where.SWhere_TraitWhere_item-decl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="docblock item-decl"><pre class="rust trait"><code>pub trait TraitWhere {
type <a href="#associatedtype.Item" class="associatedtype">Item</a>&lt;'a&gt;<br />&#160;&#160;&#160; <span class="where">where<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Self: 'a</span>;
}</code></pre></div>
13 changes: 13 additions & 0 deletions src/test/rustdoc/where.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(generic_associated_types)]
#![crate_name = "foo"]

pub trait MyTrait { fn dummy(&self) { } }
Expand All @@ -19,6 +20,18 @@ impl<D> Delta<D> where D: MyTrait {

pub struct Echo<E>(E);

// @has 'foo/struct.Simd.html'
// @snapshot SWhere_Simd_item-decl - '//div[@class="docblock item-decl"]'
pub struct Simd<T, const LANES: usize>([T; LANES])
where
T: Sized;

// @has 'foo/trait.TraitWhere.html'
// @snapshot SWhere_TraitWhere_item-decl - '//div[@class="docblock item-decl"]'
pub trait TraitWhere {
type Item<'a> where Self: 'a;
}

// @has foo/struct.Echo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
// "impl<E> MyTrait for Echo<E> where E: MyTrait"
// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header in-band"]' \
Expand Down

0 comments on commit f6c7f10

Please sign in to comment.