Skip to content

Commit f236b68

Browse files
authored
Rollup merge of #98806 - GuillaumeGomez:decl-trailing-whitespace, r=notriddle
Fix long declaration trailing whitespace Fixes #98803. Interestingly enough, it even simplifies the code a bit. r? `@notriddle`
2 parents 47456ad + 69f7a62 commit f236b68

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

src/librustdoc/html/format.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,6 @@ impl clean::FnDecl {
12831283
let mut args = Buffer::html();
12841284
let mut args_plain = Buffer::new();
12851285
for (i, input) in self.inputs.values.iter().enumerate() {
1286-
if i == 0 {
1287-
args.push_str("<br>");
1288-
}
1289-
12901286
if let Some(selfty) = input.to_self() {
12911287
match selfty {
12921288
clean::SelfValue => {
@@ -1312,8 +1308,7 @@ impl clean::FnDecl {
13121308
}
13131309
} else {
13141310
if i > 0 {
1315-
args.push_str(" <br>");
1316-
args_plain.push_str(" ");
1311+
args.push_str("<br>");
13171312
}
13181313
if input.is_const {
13191314
args.push_str("const ");
@@ -1360,13 +1355,14 @@ impl clean::FnDecl {
13601355
let full_pad = format!("<br>{}", "&nbsp;".repeat(indent + 4));
13611356
let close_pad = format!("<br>{}", "&nbsp;".repeat(indent));
13621357
format!(
1363-
"({args}{close}){arrow}",
1358+
"({pad}{args}{close}){arrow}",
1359+
pad = if self.inputs.values.is_empty() { "" } else { &full_pad },
13641360
args = args.replace("<br>", &full_pad),
13651361
close = close_pad,
13661362
arrow = arrow
13671363
)
13681364
} else {
1369-
format!("({args}){arrow}", args = args.replace("<br>", ""), arrow = arrow)
1365+
format!("({args}){arrow}", args = args.replace("<br>", " "), arrow = arrow)
13701366
};
13711367

13721368
if f.alternate() {

src/test/rustdoc/assoc-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// @has assoc_types/trait.Index.html
44
pub trait Index<I: ?Sized> {
5-
// @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized'
5+
// @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized'
66
type Output: ?Sized;
77
// @has - '//*[@id="tymethod.index"]//h4[@class="code-header"]' \
88
// "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<code>pub trait Write {
2+
fn <a href="#tymethod.poll_write" class="fnname">poll_write</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;buf: &amp;mut [<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
3+
<span class="item-spacer" /> fn <a href="#tymethod.poll_flush" class="fnname">poll_flush</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
4+
<span class="item-spacer" /> fn <a href="#tymethod.poll_close" class="fnname">poll_close</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
5+
6+
fn <a href="#method.poll_write_vectored" class="fnname">poll_write_vectored</a>(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cx: &amp;mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;bufs: &amp;[<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]<br />&#160;&#160;&#160;&#160;) -&gt; <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt; { ... }
7+
}</code>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/98803>.
2+
3+
#![crate_name = "foo"]
4+
5+
pub struct Error;
6+
7+
// @has 'foo/trait.Write.html'
8+
9+
pub trait Write {
10+
// @snapshot 'declaration' - '//*[@class="docblock item-decl"]//code'
11+
fn poll_write(
12+
self: Option<String>,
13+
cx: &mut Option<String>,
14+
buf: &mut [usize]
15+
) -> Option<Result<usize, Error>>;
16+
fn poll_flush(
17+
self: Option<String>,
18+
cx: &mut Option<String>
19+
) -> Option<Result<(), Error>>;
20+
fn poll_close(
21+
self: Option<String>,
22+
cx: &mut Option<String>,
23+
) -> Option<Result<(), Error>>;
24+
25+
fn poll_write_vectored(
26+
self: Option<String>,
27+
cx: &mut Option<String>,
28+
bufs: &[usize]
29+
) -> Option<Result<usize, Error>> {}
30+
}

0 commit comments

Comments
 (0)