From b17cf7a493bd9e80607ba0eeafcc2c22730f056c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 2 Jul 2022 12:43:07 +0200 Subject: [PATCH 1/2] Remove unwanted trailing whitespaces for long declarations --- src/librustdoc/html/format.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 056eda089c1de..5584ecd287a53 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1283,10 +1283,6 @@ impl clean::FnDecl { let mut args = Buffer::html(); let mut args_plain = Buffer::new(); for (i, input) in self.inputs.values.iter().enumerate() { - if i == 0 { - args.push_str("
"); - } - if let Some(selfty) = input.to_self() { match selfty { clean::SelfValue => { @@ -1312,8 +1308,7 @@ impl clean::FnDecl { } } else { if i > 0 { - args.push_str("
"); - args_plain.push_str(" "); + args.push_str("
"); } if input.is_const { args.push_str("const "); @@ -1360,13 +1355,14 @@ impl clean::FnDecl { let full_pad = format!("
{}", " ".repeat(indent + 4)); let close_pad = format!("
{}", " ".repeat(indent)); format!( - "({args}{close}){arrow}", + "({pad}{args}{close}){arrow}", + pad = if self.inputs.values.is_empty() { "" } else { &full_pad }, args = args.replace("
", &full_pad), close = close_pad, arrow = arrow ) } else { - format!("({args}){arrow}", args = args.replace("
", ""), arrow = arrow) + format!("({args}){arrow}", args = args.replace("
", " "), arrow = arrow) }; if f.alternate() { From 69f7a6216ec219852e17f93d7ce4de9e79a0b930 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 2 Jul 2022 12:43:33 +0200 Subject: [PATCH 2/2] Add test for trailing whitespace in long declaration --- src/test/rustdoc/assoc-types.rs | 2 +- .../decl-trailing-whitespace.declaration.html | 7 +++++ src/test/rustdoc/decl-trailing-whitespace.rs | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/decl-trailing-whitespace.declaration.html create mode 100644 src/test/rustdoc/decl-trailing-whitespace.rs diff --git a/src/test/rustdoc/assoc-types.rs b/src/test/rustdoc/assoc-types.rs index d9e4ffab1c7d5..a9e5b8d001928 100644 --- a/src/test/rustdoc/assoc-types.rs +++ b/src/test/rustdoc/assoc-types.rs @@ -2,7 +2,7 @@ // @has assoc_types/trait.Index.html pub trait Index { - // @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized' + // @has - '//*[@id="associatedtype.Output"]//h4[@class="code-header"]' 'type Output: ?Sized' type Output: ?Sized; // @has - '//*[@id="tymethod.index"]//h4[@class="code-header"]' \ // "fn index<'a>(&'a self, index: I) -> &'a Self::Output" diff --git a/src/test/rustdoc/decl-trailing-whitespace.declaration.html b/src/test/rustdoc/decl-trailing-whitespace.declaration.html new file mode 100644 index 0000000000000..e60caaeff383c --- /dev/null +++ b/src/test/rustdoc/decl-trailing-whitespace.declaration.html @@ -0,0 +1,7 @@ +pub trait Write { + fn poll_write(
        self: Option<String>,
        cx: &mut Option<String>,
        buf: &mut [usize]
    ) -> Option<Result<usize, Error>>; + fn poll_flush(
        self: Option<String>,
        cx: &mut Option<String>
    ) -> Option<Result<(), Error>>; + fn poll_close(
        self: Option<String>,
        cx: &mut Option<String>
    ) -> Option<Result<(), Error>>; + + fn poll_write_vectored(
        self: Option<String>,
        cx: &mut Option<String>,
        bufs: &[usize]
    ) -> Option<Result<usize, Error>> { ... } +}
diff --git a/src/test/rustdoc/decl-trailing-whitespace.rs b/src/test/rustdoc/decl-trailing-whitespace.rs new file mode 100644 index 0000000000000..46a2307abef02 --- /dev/null +++ b/src/test/rustdoc/decl-trailing-whitespace.rs @@ -0,0 +1,30 @@ +// Regression test for . + +#![crate_name = "foo"] + +pub struct Error; + +// @has 'foo/trait.Write.html' + +pub trait Write { + // @snapshot 'declaration' - '//*[@class="docblock item-decl"]//code' + fn poll_write( + self: Option, + cx: &mut Option, + buf: &mut [usize] + ) -> Option>; + fn poll_flush( + self: Option, + cx: &mut Option + ) -> Option>; + fn poll_close( + self: Option, + cx: &mut Option, + ) -> Option>; + + fn poll_write_vectored( + self: Option, + cx: &mut Option, + bufs: &[usize] + ) -> Option> {} +}