about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-06-25 22:34:30 +0200
committerGitHub <noreply@github.com>2023-06-25 22:34:30 +0200
commit32995d87e62f93074686a056e41d11bb1a29aa73 (patch)
tree045af45f12c9142cda0d0a71bffa6a7c3a0ed1ce
parentaa8a885cc1e36211c6c0da15089ea61673ce6678 (diff)
parentd23c334707408057915a706351ac32b2db09d8c3 (diff)
downloadrust-32995d87e62f93074686a056e41d11bb1a29aa73.tar.gz
rust-32995d87e62f93074686a056e41d11bb1a29aa73.zip
Rollup merge of #113013 - fmease:rustdoc-decl-line-wrapping-slim-arg-list, r=camelid
rustdoc: get rid of extra line when line-wrapping fn decls with empty arg list

Fixes https://github.com/bevyengine/bevy/issues/8898#issuecomment-1605683417:

![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.
-rw-r--r--src/librustdoc/html/format.rs2
-rw-r--r--tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html2
-rw-r--r--tests/rustdoc/decl-line-wrapping-empty-arg-list.rs12
3 files changed, 15 insertions, 1 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index b710311c858..b4aba2993c7 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -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() {
diff --git a/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html
new file mode 100644
index 00000000000..29c08c5bd5d
--- /dev/null
+++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html
@@ -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>
\ No newline at end of file
diff --git a/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs b/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs
new file mode 100644
index 00000000000..4cfb87496b4
--- /dev/null
+++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs
@@ -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 {}
+}