Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { "&" };

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"]'
Copy link
Member Author

@fmease fmease Jun 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using @snapshot instead of @has since I couldn't figure out if it was possible to test for the presence of line breaks with it (I love the Htmldocck DSL ^^).

pub fn create() -> Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000 {
loop {}
}