From d23c334707408057915a706351ac32b2db09d8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sat, 24 Jun 2023 23:39:35 +0200 Subject: [PATCH] rustdoc: get rid of extra line when line-wrapping fn decls with empty arg list --- src/librustdoc/html/format.rs | 2 +- .../decl-line-wrapping-empty-arg-list.decl.html | 2 ++ tests/rustdoc/decl-line-wrapping-empty-arg-list.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html create mode 100644 tests/rustdoc/decl-line-wrapping-empty-arg-list.rs diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index b710311c85872..b4aba2993c7fd 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 { "&" }; 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 0000000000000..29c08c5bd5dec --- /dev/null +++ b/tests/rustdoc/decl-line-wrapping-empty-arg-list.decl.html @@ -0,0 +1,2 @@ +
pub fn create(
+) -> Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000
\ 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 0000000000000..4cfb87496b486 --- /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 {} +}