rustdoc: trait bound formatting
rustdoc: fix item-spacer rustdoc: use proper comment style rustdoc: change formatting where clauses for traits rustdoc: remove semicolon from provided methods update provided methods formatting
This commit is contained in:
parent
4aa6afa7f8
commit
71a147df1f
11 changed files with 65 additions and 22 deletions
|
@ -353,7 +353,11 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
} else {
|
} else {
|
||||||
let mut br_with_padding = String::with_capacity(6 * indent + 28);
|
let mut br_with_padding = String::with_capacity(6 * indent + 28);
|
||||||
br_with_padding.push_str("<br>");
|
br_with_padding.push_str("<br>");
|
||||||
for _ in 0..indent + 4 {
|
|
||||||
|
let padding_amout =
|
||||||
|
if ending == Ending::Newline { indent + 4 } else { indent + "fn where ".len() };
|
||||||
|
|
||||||
|
for _ in 0..padding_amout {
|
||||||
br_with_padding.push_str(" ");
|
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("<br>", &br_with_padding);
|
||||||
|
@ -367,8 +371,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
if indent == 0 {
|
if indent == 0 {
|
||||||
format!("<br><span class=\"where\">where{where_preds}</span>")
|
format!("<br><span class=\"where\">where{where_preds}</span>")
|
||||||
} else {
|
} else {
|
||||||
|
// put the first one on the same line as the 'where' keyword
|
||||||
|
let where_preds = where_preds.replacen(&br_with_padding, " ", 1);
|
||||||
|
|
||||||
let mut clause = br_with_padding;
|
let mut clause = br_with_padding;
|
||||||
clause.truncate(clause.len() - 4);
|
clause.truncate(clause.len() - "where ".len());
|
||||||
|
|
||||||
write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
|
write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
|
||||||
clause
|
clause
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,6 +645,10 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||||
if count_consts != 0 && count_methods != 0 {
|
if count_consts != 0 && count_methods != 0 {
|
||||||
w.write_str("\n");
|
w.write_str("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !required_methods.is_empty() {
|
||||||
|
write!(w, " // Required method{}\n", pluralize(required_methods.len()));
|
||||||
|
}
|
||||||
for (pos, m) in required_methods.iter().enumerate() {
|
for (pos, m) in required_methods.iter().enumerate() {
|
||||||
render_assoc_item(
|
render_assoc_item(
|
||||||
w,
|
w,
|
||||||
|
@ -663,6 +667,10 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||||
if !required_methods.is_empty() && !provided_methods.is_empty() {
|
if !required_methods.is_empty() && !provided_methods.is_empty() {
|
||||||
w.write_str("\n");
|
w.write_str("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !provided_methods.is_empty() {
|
||||||
|
write!(w, " // Provided method{}\n", pluralize(provided_methods.len()));
|
||||||
|
}
|
||||||
for (pos, m) in provided_methods.iter().enumerate() {
|
for (pos, m) in provided_methods.iter().enumerate() {
|
||||||
render_assoc_item(
|
render_assoc_item(
|
||||||
w,
|
w,
|
||||||
|
@ -672,16 +680,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||||
cx,
|
cx,
|
||||||
RenderMode::Normal,
|
RenderMode::Normal,
|
||||||
);
|
);
|
||||||
match *m.kind {
|
|
||||||
clean::MethodItem(ref inner, _)
|
w.write_str(" { ... }\n");
|
||||||
if !inner.generics.where_predicates.is_empty() =>
|
|
||||||
{
|
|
||||||
w.write_str(",\n { ... }\n");
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
w.write_str(" { ... }\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos < provided_methods.len() - 1 {
|
if pos < provided_methods.len() - 1 {
|
||||||
w.write_str("<span class=\"item-spacer\"></span>");
|
w.write_str("<span class=\"item-spacer\"></span>");
|
||||||
|
|
|
@ -1176,6 +1176,7 @@ a.test-arrow:hover {
|
||||||
.item-spacer {
|
.item-spacer {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 12px;
|
height: 12px;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.out-of-band > span.since {
|
.out-of-band > span.since {
|
||||||
|
|
|
@ -4,3 +4,15 @@ pub trait Foo {
|
||||||
fn bar(&self);
|
fn bar(&self);
|
||||||
fn foo(&mut self) {}
|
fn foo(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Bar {
|
||||||
|
fn bar(&self);
|
||||||
|
fn foo1(&mut self) {}
|
||||||
|
fn foo2(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Baz {
|
||||||
|
fn bar1(&self);
|
||||||
|
fn bar2(&self);
|
||||||
|
fn foo(&mut self) {}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<code>pub trait Write {
|
<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>>>;
|
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_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>>>;
|
<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>>>;
|
||||||
|
|
||||||
|
// 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>(<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>>> { ... }
|
||||||
}</code>
|
}</code>
|
|
@ -4,6 +4,18 @@
|
||||||
extern crate inline_default_methods;
|
extern crate inline_default_methods;
|
||||||
|
|
||||||
// @has inline_default_methods/trait.Foo.html
|
// @has inline_default_methods/trait.Foo.html
|
||||||
// @has - '//pre[@class="rust item-decl"]' 'fn bar(&self);'
|
// @has - '//pre[@class="rust item-decl"]' '// Required method fn bar(&self);'
|
||||||
// @has - '//pre[@class="rust item-decl"]' 'fn foo(&mut self) { ... }'
|
// @has - '//pre[@class="rust item-decl"]' '// Provided method fn foo(&mut self)'
|
||||||
pub use inline_default_methods::Foo;
|
pub use inline_default_methods::Foo;
|
||||||
|
|
||||||
|
// @has inline_default_methods/trait.Bar.html
|
||||||
|
// @has - '//pre[@class="rust item-decl"]' '// Required method fn bar(&self);'
|
||||||
|
// @has - '//pre[@class="rust item-decl"]' '// Provided methods fn foo1(&mut self)'
|
||||||
|
// @has - '//pre[@class="rust item-decl"]' 'fn foo2(&mut self)'
|
||||||
|
pub use inline_default_methods::Bar;
|
||||||
|
|
||||||
|
// @has inline_default_methods/trait.Baz.html
|
||||||
|
// @has - '//pre[@class="rust item-decl"]' '// Required methods fn bar1(&self);'
|
||||||
|
// @has - '//pre[@class="rust item-decl"]' 'fn bar2(&self);'
|
||||||
|
// @has - '//pre[@class="rust item-decl"]' '// Provided method fn foo(&mut self)'
|
||||||
|
pub use inline_default_methods::Baz;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
extern crate issue_85454;
|
extern crate issue_85454;
|
||||||
|
|
||||||
// @has foo/trait.FromResidual.html
|
// @has foo/trait.FromResidual.html
|
||||||
// @has - '//pre[@class="rust item-decl"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { fn from_residual(residual: R) -> Self; }'
|
// @has - '//pre[@class="rust item-decl"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { // Required method fn from_residual(residual: R) -> Self; }'
|
||||||
pub trait FromResidual<R = <Self as Try>::Residual> {
|
pub trait FromResidual<R = <Self as Try>::Residual> {
|
||||||
fn from_residual(residual: R) -> Self;
|
fn from_residual(residual: R) -> Self;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,6 @@ pub enum ControlFlow<B, C = ()> {
|
||||||
|
|
||||||
pub mod reexport {
|
pub mod reexport {
|
||||||
// @has foo/reexport/trait.FromResidual.html
|
// @has foo/reexport/trait.FromResidual.html
|
||||||
// @has - '//pre[@class="rust item-decl"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { fn from_residual(residual: R) -> Self; }'
|
// @has - '//pre[@class="rust item-decl"]' 'pub trait FromResidual<R = <Self as Try>::Residual> { // Required method fn from_residual(residual: R) -> Self; }'
|
||||||
pub use issue_85454::*;
|
pub use issue_85454::*;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<pre class="rust item-decl"><code>pub trait TraitWhere {
|
<pre class="rust item-decl"><code>pub trait TraitWhere {
|
||||||
type <a href="#associatedtype.Item" class="associatedtype">Item</a><'a><br />    <span class="where">where<br />        Self: 'a</span>;
|
type <a href="#associatedtype.Item" class="associatedtype">Item</a><'a><br />       <span class="where">where Self: 'a</span>;
|
||||||
|
|
||||||
fn <a href="#method.func" class="fn">func</a>(self)<br />    <span class="where">where<br />        Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</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<br />        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> { ... }
|
||||||
}</code></pre>
|
}</code></pre>
|
|
@ -41,6 +41,12 @@ pub trait TraitWhere {
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{ todo!() }
|
{ todo!() }
|
||||||
|
|
||||||
|
fn merge<T>(self, a: T)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
T: Sized,
|
||||||
|
{ todo!() }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @has foo/struct.Echo.html '//*[@class="impl"]//h3[@class="code-header"]' \
|
// @has foo/struct.Echo.html '//*[@class="impl"]//h3[@class="code-header"]' \
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<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<br />    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>;
|
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>;
|
||||||
|
|
||||||
|
// Required methods
|
||||||
fn <a href="#tymethod.to_owned" class="fn">to_owned</a>(&self) -> Self::<a class="associatedtype" href="trait.ToOwned.html#associatedtype.Owned" title="type foo::ToOwned::Owned">Owned</a>;
|
fn <a href="#tymethod.to_owned" class="fn">to_owned</a>(&self) -> Self::<a class="associatedtype" href="trait.ToOwned.html#associatedtype.Owned" title="type foo::ToOwned::Owned">Owned</a>;
|
||||||
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fn">whatever</a>(&self) -> T;
|
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fn">whatever</a>(&self) -> T;
|
||||||
}</code></pre>
|
}</code></pre>
|
|
@ -1,6 +1,7 @@
|
||||||
<pre class="rust item-decl"><code>pub trait ToOwned2<T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> {
|
<pre class="rust item-decl"><code>pub trait ToOwned2<T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> {
|
||||||
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>;
|
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>;
|
||||||
|
|
||||||
|
// Required methods
|
||||||
fn <a href="#tymethod.to_owned" class="fn">to_owned</a>(&self) -> Self::<a class="associatedtype" href="trait.ToOwned2.html#associatedtype.Owned" title="type foo::ToOwned2::Owned">Owned</a>;
|
fn <a href="#tymethod.to_owned" class="fn">to_owned</a>(&self) -> Self::<a class="associatedtype" href="trait.ToOwned2.html#associatedtype.Owned" title="type foo::ToOwned2::Owned">Owned</a>;
|
||||||
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fn">whatever</a>(&self) -> T;
|
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fn">whatever</a>(&self) -> T;
|
||||||
}</code></pre>
|
}</code></pre>
|
Loading…
Add table
Reference in a new issue