Skip to content

Commit

Permalink
Rollup merge of #113013 - fmease:rustdoc-decl-line-wrapping-slim-arg-…
Browse files Browse the repository at this point in the history
…list, r=camelid

rustdoc: get rid of extra line when line-wrapping fn decls with empty arg list

Fixes bevyengine/bevy#8898 (comment):

![Screenshot 2023-06-24 at 23-42-53 any_with_component in bevy_ecs schedule common_conditions - Rust](https://github.com/rust-lang/rust/assets/14913065/4646eba6-b186-4d78-96d9-aad716a4ef5d)

It now prints as shown below (which conforms to the style guide):

```rs
pub fn any_with_component<T: Component>(
) -> impl FnMut(Query<'_, '_, (), With<T>>) -> bool + Clone
```

The bug was introduced in #109011.
  • Loading branch information
matthiaskrgr committed Jun 25, 2023
2 parents aa8a885 + d23c334 commit 32995d8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ impl clean::FnDecl {
let amp = if f.alternate() { "&" } else { "&amp;" };

write!(f, "(")?;
if let Some(n) = line_wrapping_indent {
if let Some(n) = line_wrapping_indent && !self.inputs.values.is_empty() {
write!(f, "\n{}", Indent(n + 4))?;
}
for (i, input) in self.inputs.values.iter().enumerate() {
Expand Down
2 changes: 2 additions & 0 deletions tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<pre class="rust item-decl"><code>pub fn create(
) -&gt; <a class="struct" href="struct.Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000.html" title="struct decl_line_wrapping_empty_arg_list::Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000">Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000</a></code></pre>
12 changes: 12 additions & 0 deletions tests/rustdoc/decl-line-wrapping-empty-arg-list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Ensure that we don't add an extra line containing nothing but whitespace in between the two
// parentheses of an empty argument list when line-wrapping a function declaration.

// ignore-tidy-linelength

pub struct Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000;

// @has 'decl_line_wrapping_empty_arg_list/fn.create.html'
// @snapshot decl - '//pre[@class="rust item-decl"]'
pub fn create() -> Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000 {
loop {}
}

0 comments on commit 32995d8

Please sign in to comment.