mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
rustdoc: use a newline instead of <br>
to format code headers
Since these elements now use `white-space: pre-wrap` since
784665d4ce
, it's fine to use newlines
for formatting, which is smaller and a bit less complicated.
This commit is contained in:
parent
5dd0e1b7ae
commit
8307fd7901
@ -289,7 +289,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||
if f.alternate() {
|
||||
f.write_str(" ")?;
|
||||
} else {
|
||||
f.write_str("<br>")?;
|
||||
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>");
|
||||
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>", &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, "<span class=\"where fmt-newline\">where{where_preds},</span>")?;
|
||||
clause
|
||||
} else {
|
||||
// insert a <br> 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!("<br><span class=\"where\">where{where_preds}</span>")
|
||||
format!("\n<span class=\"where\">where{where_preds}</span>")
|
||||
} 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.
|
||||
/// <br>Used to determine line-wrapping.
|
||||
/// This is expected to go into a `<pre>`/`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("<br>");
|
||||
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(",<br> ...");
|
||||
args.push_str(",\n ...");
|
||||
args_plain.push_str(", ...");
|
||||
}
|
||||
|
||||
@ -1399,26 +1400,22 @@ impl clean::FnDecl {
|
||||
|
||||
let declaration_len = header_len + args_plain.len() + arrow_plain.len();
|
||||
let output = if declaration_len > 80 {
|
||||
let full_pad = format!("<br>{}", " ".repeat(indent + 4));
|
||||
let close_pad = format!("<br>{}", " ".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("<br>", &full_pad),
|
||||
args = args.replace("\n", &full_pad),
|
||||
close = close_pad,
|
||||
arrow = arrow
|
||||
)
|
||||
} else {
|
||||
format!("({args}){arrow}", args = args.replace("<br>", " "), arrow = arrow)
|
||||
format!("({args}){arrow}", args = args.replace("\n", " "), arrow = arrow)
|
||||
};
|
||||
|
||||
if f.alternate() {
|
||||
write!(f, "{}", output.replace("<br>", "\n"))
|
||||
} else {
|
||||
write!(f, "{}", output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>(
|
||||
visibility: Option<ty::Visibility<DefId>>,
|
||||
|
@ -1,9 +1,23 @@
|
||||
<code>pub trait Write {
|
||||
// Required methods
|
||||
fn <a href="#tymethod.poll_write" class="fn">poll_write</a>(<br />        self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,<br />        cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,<br />        buf: &mut [<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]<br />    ) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>>;
|
||||
<span class="item-spacer" /> fn <a href="#tymethod.poll_flush" class="fn">poll_flush</a>(<br />        self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,<br />        cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>><br />    ) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>>;
|
||||
<span class="item-spacer" /> fn <a href="#tymethod.poll_close" class="fn">poll_close</a>(<br />        self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,<br />        cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>><br />    ) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>>;
|
||||
fn <a href="#tymethod.poll_write" class="fn">poll_write</a>(
|
||||
self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,
|
||||
cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,
|
||||
buf: &mut [<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]
|
||||
) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>>;
|
||||
<span class="item-spacer" /> fn <a href="#tymethod.poll_flush" class="fn">poll_flush</a>(
|
||||
self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,
|
||||
cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>
|
||||
) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>>;
|
||||
<span class="item-spacer" /> fn <a href="#tymethod.poll_close" class="fn">poll_close</a>(
|
||||
self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,
|
||||
cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>
|
||||
) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>>;
|
||||
|
||||
// Provided method
|
||||
fn <a href="#method.poll_write_vectored" class="fn">poll_write_vectored</a>(<br />        self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,<br />        cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,<br />        bufs: &[<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]<br />    ) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>> { ... }
|
||||
fn <a href="#method.poll_write_vectored" class="fn">poll_write_vectored</a>(
|
||||
self: <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,
|
||||
cx: &mut <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="struct" href="{{channel}}/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>>,
|
||||
bufs: &[<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>]
|
||||
) -> <a class="enum" href="{{channel}}/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="enum" href="{{channel}}/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="{{channel}}/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>>> { ... }
|
||||
}</code>
|
@ -1 +1,3 @@
|
||||
<pre class="rust item-decl"><code>pub struct Simd<T>(_)<br /><span class="where">where<br />    T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre>
|
||||
<pre class="rust item-decl"><code>pub struct Simd<T>(_)
|
||||
<span class="where">where
|
||||
T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre>
|
@ -1,8 +1,13 @@
|
||||
<pre class="rust item-decl"><code>pub trait TraitWhere {
|
||||
type <a href="#associatedtype.Item" class="associatedtype">Item</a><'a><br />       <span class="where">where Self: 'a</span>;
|
||||
type <a href="#associatedtype.Item" class="associatedtype">Item</a><'a>
|
||||
<span class="where">where Self: 'a</span>;
|
||||
|
||||
// Provided methods
|
||||
fn <a href="#method.func" class="fn">func</a>(self)<br />       <span class="where">where Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer" /> fn <a href="#method.lines" class="fn">lines</a>(self) -> <a class="struct" href="{{channel}}/std/io/struct.Lines.html" title="struct std::io::Lines">Lines</a><Self><br />       <span class="where">where Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer" /> fn <a href="#method.merge" class="fn">merge</a><T>(self, a: T)<br />       <span class="where">where Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,<br />             T: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
fn <a href="#method.func" class="fn">func</a>(self)
|
||||
<span class="where">where Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer" /> fn <a href="#method.lines" class="fn">lines</a>(self) -> <a class="struct" href="{{channel}}/std/io/struct.Lines.html" title="struct std::io::Lines">Lines</a><Self>
|
||||
<span class="where">where Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
<span class="item-spacer" /> fn <a href="#method.merge" class="fn">merge</a><T>(self, a: T)
|
||||
<span class="where">where Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||||
T: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
||||
}</code></pre>
|
@ -1,4 +1,5 @@
|
||||
<pre class="rust item-decl"><code>pub enum Cow<'a, B><span class="where fmt-newline">where<br />    B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</span>{
|
||||
<pre class="rust item-decl"><code>pub enum Cow<'a, B><span class="where fmt-newline">where
|
||||
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</span>{
|
||||
Borrowed(<a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a B</a>),
|
||||
Whatever(<a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>),
|
||||
}</code></pre>
|
@ -1,4 +1,5 @@
|
||||
<pre class="rust item-decl"><code>pub struct Struct<'a, B><span class="where fmt-newline">where<br />    B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</span>{
|
||||
<pre class="rust item-decl"><code>pub struct Struct<'a, B><span class="where fmt-newline">where
|
||||
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</span>{
|
||||
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a B</a>,
|
||||
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>,
|
||||
}</code></pre>
|
@ -1,4 +1,5 @@
|
||||
<pre class="rust item-decl"><code>pub trait ToOwned<T><span class="where fmt-newline">where<br />    T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</span>{
|
||||
<pre class="rust item-decl"><code>pub trait ToOwned<T><span class="where fmt-newline">where
|
||||
T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</span>{
|
||||
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>;
|
||||
|
||||
// Required methods
|
||||
|
@ -1,3 +1,4 @@
|
||||
<pre class="rust item-decl"><code>pub union Union<'a, B><span class="where fmt-newline">where<br />    B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</span>{
|
||||
<pre class="rust item-decl"><code>pub union Union<'a, B><span class="where fmt-newline">where
|
||||
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</span>{
|
||||
/* private fields */
|
||||
}</code></pre>
|
Loading…
Reference in New Issue
Block a user