diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index a59cfbea885..8a7a8ea5fd1 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -289,7 +289,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>( if f.alternate() { f.write_str(" ")?; } else { - f.write_str("
")?; + f.write_str("\n")?; } match pred { @@ -352,7 +352,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>( } } else { let mut br_with_padding = String::with_capacity(6 * indent + 28); - br_with_padding.push_str("
"); + br_with_padding.push_str("\n"); let padding_amout = if ending == Ending::Newline { indent + 4 } else { indent + "fn where ".len() }; @@ -360,16 +360,16 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>( for _ in 0..padding_amout { br_with_padding.push_str(" "); } - let where_preds = where_preds.to_string().replace("
", &br_with_padding); + let where_preds = where_preds.to_string().replace("\n", &br_with_padding); if ending == Ending::Newline { let mut clause = " ".repeat(indent.saturating_sub(1)); write!(clause, "where{where_preds},")?; clause } else { - // insert a
tag after a single space but before multiple spaces at the start + // insert a newline after a single space but before multiple spaces at the start if indent == 0 { - format!("
where{where_preds}") + format!("\nwhere{where_preds}") } else { // put the first one on the same line as the 'where' keyword let where_preds = where_preds.replacen(&br_with_padding, " ", 1); @@ -1315,7 +1315,8 @@ impl clean::FnDecl { /// * `header_len`: The length of the function header and name. In other words, the number of /// characters in the function declaration up to but not including the parentheses. - ///
Used to determine line-wrapping. + /// This is expected to go into a `
`/`code-header` block, so indentation and newlines
+    ///   are preserved.
     /// * `indent`: The number of spaces to indent each successive line with, if line-wrapping is
     ///   necessary.
     pub(crate) fn full_print<'a, 'tcx: 'a>(
@@ -1363,7 +1364,7 @@ impl clean::FnDecl {
                 }
             } else {
                 if i > 0 {
-                    args.push_str("
"); + args.push_str("\n"); } if input.is_const { args.push_str("const "); @@ -1389,7 +1390,7 @@ impl clean::FnDecl { let mut args = args.into_inner(); if self.c_variadic { - args.push_str(",
..."); + args.push_str(",\n ..."); args_plain.push_str(", ..."); } @@ -1399,24 +1400,20 @@ impl clean::FnDecl { let declaration_len = header_len + args_plain.len() + arrow_plain.len(); let output = if declaration_len > 80 { - let full_pad = format!("
{}", " ".repeat(indent + 4)); - let close_pad = format!("
{}", " ".repeat(indent)); + let full_pad = format!("\n{}", " ".repeat(indent + 4)); + let close_pad = format!("\n{}", " ".repeat(indent)); format!( "({pad}{args}{close}){arrow}", pad = if self.inputs.values.is_empty() { "" } else { &full_pad }, - args = args.replace("
", &full_pad), + args = args.replace("\n", &full_pad), close = close_pad, arrow = arrow ) } else { - format!("({args}){arrow}", args = args.replace("
", " "), arrow = arrow) + format!("({args}){arrow}", args = args.replace("\n", " "), arrow = arrow) }; - if f.alternate() { - write!(f, "{}", output.replace("
", "\n")) - } else { - write!(f, "{}", output) - } + write!(f, "{}", output) } } diff --git a/tests/rustdoc/async-fn.rs b/tests/rustdoc/async-fn.rs index 3db344af674..70bcbcb6ff4 100644 --- a/tests/rustdoc/async-fn.rs +++ b/tests/rustdoc/async-fn.rs @@ -77,7 +77,7 @@ struct AsyncFdReadyGuard<'a, T> { x: &'a T } impl Foo { // @has async_fn/struct.Foo.html - // @has - '//*[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar) -> impl Iterator' + // @has - '//*[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar ) -> impl Iterator' pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator {} // taken from `tokio` as an example of a method that was particularly bad before // @has - '//*[@class="method"]' "pub async fn readable(&self) -> Result, ()>" diff --git a/tests/rustdoc/const-generics/const-generics-docs.rs b/tests/rustdoc/const-generics/const-generics-docs.rs index ade70bbe80d..cbda095424b 100644 --- a/tests/rustdoc/const-generics/const-generics-docs.rs +++ b/tests/rustdoc/const-generics/const-generics-docs.rs @@ -31,7 +31,7 @@ impl Trait<{1 + 2}> for u8 {} impl Trait for [u8; N] {} // @has foo/struct.Foo.html '//pre[@class="rust item-decl"]' \ -// 'pub struct Foowhere u8: Trait' +// 'pub struct Foo where u8: Trait' pub struct Foo where u8: Trait; // @has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar(_)' pub struct Bar([T; N]); diff --git a/tests/rustdoc/decl-trailing-whitespace.declaration.html b/tests/rustdoc/decl-trailing-whitespace.declaration.html index a2500de79a0..d73393633f3 100644 --- a/tests/rustdoc/decl-trailing-whitespace.declaration.html +++ b/tests/rustdoc/decl-trailing-whitespace.declaration.html @@ -1,9 +1,23 @@ pub trait Write { // Required methods - 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( + 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>>; // Provided method - fn poll_write_vectored(
        self: Option<String>,
        cx: &mut Option<String>,
        bufs: &[usize]
    ) -> Option<Result<usize, Error>> { ... } -}
+ fn poll_write_vectored( + self: Option<String>, + cx: &mut Option<String>, + bufs: &[usize] + ) -> Option<Result<usize, Error>> { ... } +} \ No newline at end of file diff --git a/tests/rustdoc/generic-associated-types/gats.rs b/tests/rustdoc/generic-associated-types/gats.rs index bcead3115fe..7ab82bb5829 100644 --- a/tests/rustdoc/generic-associated-types/gats.rs +++ b/tests/rustdoc/generic-associated-types/gats.rs @@ -2,7 +2,7 @@ // @has foo/trait.LendingIterator.html pub trait LendingIterator { - // @has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' "type Item<'a>where Self: 'a" + // @has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' "type Item<'a> where Self: 'a" type Item<'a> where Self: 'a; // @has - '//*[@id="tymethod.next"]//h4[@class="code-header"]' \ @@ -23,7 +23,7 @@ impl LendingIterator for () { pub struct Infinite(T); // @has foo/trait.LendingIterator.html -// @has - '//*[@id="associatedtype.Item-2"]//h4[@class="code-header"]' "type Item<'a>where Self: 'a = &'a T" +// @has - '//*[@id="associatedtype.Item-2"]//h4[@class="code-header"]' "type Item<'a> where Self: 'a = &'a T" impl LendingIterator for Infinite { type Item<'a> where Self: 'a = &'a T; diff --git a/tests/rustdoc/inline_cross/impl_trait.rs b/tests/rustdoc/inline_cross/impl_trait.rs index 7d810ab4813..b6a1552bc00 100644 --- a/tests/rustdoc/inline_cross/impl_trait.rs +++ b/tests/rustdoc/inline_cross/impl_trait.rs @@ -11,7 +11,7 @@ pub use impl_trait_aux::func; // @has impl_trait/fn.func2.html // @has - '//pre[@class="rust item-decl"]' "func2(" // @has - '//pre[@class="rust item-decl"]' "_x: impl Deref> + Iterator," -// @has - '//pre[@class="rust item-decl"]' "_y: impl Iterator)" +// @has - '//pre[@class="rust item-decl"]' "_y: impl Iterator )" // @!has - '//pre[@class="rust item-decl"]' 'where' pub use impl_trait_aux::func2; diff --git a/tests/rustdoc/issue-34928.rs b/tests/rustdoc/issue-34928.rs index 91b67757453..4184086f622 100644 --- a/tests/rustdoc/issue-34928.rs +++ b/tests/rustdoc/issue-34928.rs @@ -2,5 +2,5 @@ pub trait Bar {} -// @has foo/struct.Foo.html '//pre' 'pub struct Foo(pub T)where T: Bar;' +// @has foo/struct.Foo.html '//pre' 'pub struct Foo(pub T) where T: Bar;' pub struct Foo(pub T) where T: Bar; diff --git a/tests/rustdoc/reexports-priv.rs b/tests/rustdoc/reexports-priv.rs index 84ea4ad2c9e..571d7f06fdc 100644 --- a/tests/rustdoc/reexports-priv.rs +++ b/tests/rustdoc/reexports-priv.rs @@ -98,7 +98,7 @@ pub mod outer { pub use reexports::foo; // @has 'foo/outer/inner/fn.foo_crate.html' '//pre[@class="rust item-decl"]' 'pub(crate) fn foo_crate()' pub(crate) use reexports::foo_crate; - // @has 'foo/outer/inner/fn.foo_super.html' '//pre[@class="rust item-decl"]' 'pub(in outer) fn foo_super()' + // @has 'foo/outer/inner/fn.foo_super.html' '//pre[@class="rust item-decl"]' 'pub(in outer) fn foo_super( )' pub(super) use::reexports::foo_super; // @!has 'foo/outer/inner/fn.foo_self.html' pub(self) use reexports::foo_self; diff --git a/tests/rustdoc/where.SWhere_Simd_item-decl.html b/tests/rustdoc/where.SWhere_Simd_item-decl.html index 6f151f2328e..ef4294c8f76 100644 --- a/tests/rustdoc/where.SWhere_Simd_item-decl.html +++ b/tests/rustdoc/where.SWhere_Simd_item-decl.html @@ -1 +1,3 @@ -
pub struct Simd<T>(_)
where
    T: MyTrait
;
\ No newline at end of file +
pub struct Simd<T>(_)
+where
+         T: MyTrait;
\ No newline at end of file diff --git a/tests/rustdoc/where.SWhere_TraitWhere_item-decl.html b/tests/rustdoc/where.SWhere_TraitWhere_item-decl.html index 858bc142f66..e8ab061e679 100644 --- a/tests/rustdoc/where.SWhere_TraitWhere_item-decl.html +++ b/tests/rustdoc/where.SWhere_TraitWhere_item-decl.html @@ -1,8 +1,13 @@
pub trait TraitWhere {
-    type Item<'a>
       where Self: 'a; + type Item<'a> + where Self: 'a; // Provided methods - fn func(self)
       where Self: Sized { ... } - fn lines(self) -> Lines<Self>
       where Self: Sized { ... } - fn merge<T>(self, a: T)
       where Self: Sized,
             T: Sized
{ ... } + fn func(self) + where Self: Sized { ... } + fn lines(self) -> Lines<Self> + where Self: Sized { ... } + fn merge<T>(self, a: T) + where Self: Sized, + T: Sized { ... } }
\ No newline at end of file diff --git a/tests/rustdoc/where.rs b/tests/rustdoc/where.rs index af3239b6947..8b8a126e89d 100644 --- a/tests/rustdoc/where.rs +++ b/tests/rustdoc/where.rs @@ -4,7 +4,7 @@ use std::io::Lines; pub trait MyTrait { fn dummy(&self) { } } -// @has foo/struct.Alpha.html '//pre' "pub struct Alpha(_)where A: MyTrait" +// @has foo/struct.Alpha.html '//pre' "pub struct Alpha(_) where A: MyTrait" pub struct Alpha(A) where A: MyTrait; // @has foo/trait.Bravo.html '//pre' "pub trait Bravowhere B: MyTrait" pub trait Bravo where B: MyTrait { fn get(&self, B: B); } diff --git a/tests/rustdoc/whitespace-after-where-clause.enum.html b/tests/rustdoc/whitespace-after-where-clause.enum.html index 904d4611036..20b60b68e88 100644 --- a/tests/rustdoc/whitespace-after-where-clause.enum.html +++ b/tests/rustdoc/whitespace-after-where-clause.enum.html @@ -1,4 +1,5 @@ -
pub enum Cow<'a, B>where
    B:
ToOwned<dyn Clone> + ?Sized + 'a,{ +
pub enum Cow<'a, B>where
+    B: ToOwned<dyn Clone> + ?Sized + 'a,{
     Borrowed(&'a B),
     Whatever(u32),
 }
\ No newline at end of file diff --git a/tests/rustdoc/whitespace-after-where-clause.struct.html b/tests/rustdoc/whitespace-after-where-clause.struct.html index 54faee9e405..948ddc499da 100644 --- a/tests/rustdoc/whitespace-after-where-clause.struct.html +++ b/tests/rustdoc/whitespace-after-where-clause.struct.html @@ -1,4 +1,5 @@ -
pub struct Struct<'a, B>where
    B: ToOwned<dyn Clone> + ?Sized + 'a,
{ +
pub struct Struct<'a, B>where
+    B: ToOwned<dyn Clone> + ?Sized + 'a,{
     pub a: &'a B,
     pub b: u32,
 }
\ No newline at end of file diff --git a/tests/rustdoc/whitespace-after-where-clause.trait.html b/tests/rustdoc/whitespace-after-where-clause.trait.html index 8a78e82dc71..0928b48e6b6 100644 --- a/tests/rustdoc/whitespace-after-where-clause.trait.html +++ b/tests/rustdoc/whitespace-after-where-clause.trait.html @@ -1,4 +1,5 @@ -
pub trait ToOwned<T>where
    T: Clone,
{ +
pub trait ToOwned<T>where
+    T: Clone,{
     type Owned;
 
     // Required methods
diff --git a/tests/rustdoc/whitespace-after-where-clause.union.html b/tests/rustdoc/whitespace-after-where-clause.union.html
index 03a26280ba2..38b6cb8b5c6 100644
--- a/tests/rustdoc/whitespace-after-where-clause.union.html
+++ b/tests/rustdoc/whitespace-after-where-clause.union.html
@@ -1,3 +1,4 @@
-
pub union Union<'a, B>where
    B: ToOwned<dyn Clone> + ?Sized + 'a,
{ +
pub union Union<'a, B>where
+    B: ToOwned<dyn Clone> + ?Sized + 'a,{
     /* private fields */
 }
\ No newline at end of file