Rollup merge of #107615 - notriddle:notriddle/nbsp, r=GuillaumeGomez
Replace nbsp in all rustdoc code blocks Based on #106125 by `@dtolnay` — this PR fixes the line wrapping bug. Fixes #106098. This makes code copyable from rustdoc rendered documentation into a Rust source file.
This commit is contained in:
commit
f7210b3bed
@ -208,7 +208,7 @@ impl clean::GenericParamDef {
|
||||
if f.alternate() {
|
||||
write!(f, ": {:#}", print_generic_bounds(bounds, cx))?;
|
||||
} else {
|
||||
write!(f, ": {}", print_generic_bounds(bounds, cx))?;
|
||||
write!(f, ": {}", print_generic_bounds(bounds, cx))?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ impl clean::GenericParamDef {
|
||||
if f.alternate() {
|
||||
write!(f, " = {:#}", ty.print(cx))?;
|
||||
} else {
|
||||
write!(f, " = {}", ty.print(cx))?;
|
||||
write!(f, " = {}", ty.print(cx))?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,14 +226,14 @@ impl clean::GenericParamDef {
|
||||
if f.alternate() {
|
||||
write!(f, "const {}: {:#}", self.name, ty.print(cx))?;
|
||||
} else {
|
||||
write!(f, "const {}: {}", self.name, ty.print(cx))?;
|
||||
write!(f, "const {}: {}", self.name, ty.print(cx))?;
|
||||
}
|
||||
|
||||
if let Some(default) = default {
|
||||
if f.alternate() {
|
||||
write!(f, " = {:#}", default)?;
|
||||
} else {
|
||||
write!(f, " = {}", default)?;
|
||||
write!(f, " = {}", default)?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,12 +354,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||
let mut br_with_padding = String::with_capacity(6 * indent + 28);
|
||||
br_with_padding.push_str("<br>");
|
||||
for _ in 0..indent + 4 {
|
||||
br_with_padding.push_str(" ");
|
||||
br_with_padding.push_str(" ");
|
||||
}
|
||||
let where_preds = where_preds.to_string().replace("<br>", &br_with_padding);
|
||||
|
||||
if ending == Ending::Newline {
|
||||
let mut clause = " ".repeat(indent.saturating_sub(1));
|
||||
let mut clause = " ".repeat(indent.saturating_sub(1));
|
||||
write!(clause, "<span class=\"where fmt-newline\">where{where_preds},</span>")?;
|
||||
clause
|
||||
} else {
|
||||
@ -368,7 +368,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||
format!("<br><span class=\"where\">where{where_preds}</span>")
|
||||
} else {
|
||||
let mut clause = br_with_padding;
|
||||
clause.truncate(clause.len() - 4 * " ".len());
|
||||
clause.truncate(clause.len() - 4);
|
||||
write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
|
||||
clause
|
||||
}
|
||||
@ -1391,8 +1391,8 @@ 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!("<br>{}", " ".repeat(indent + 4));
|
||||
let close_pad = format!("<br>{}", " ".repeat(indent));
|
||||
format!(
|
||||
"({pad}{args}{close}){arrow}",
|
||||
pad = if self.inputs.values.is_empty() { "" } else { &full_pad },
|
||||
@ -1611,7 +1611,7 @@ impl clean::TypeBinding {
|
||||
if f.alternate() {
|
||||
write!(f, ": {:#}", print_generic_bounds(bounds, cx))?;
|
||||
} else {
|
||||
write!(f, ": {}", print_generic_bounds(bounds, cx))?;
|
||||
write!(f, ": {}", print_generic_bounds(bounds, cx))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1157,7 +1157,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
|
||||
fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]) {
|
||||
for (i, ty) in s.iter().enumerate() {
|
||||
if i > 0 {
|
||||
w.write_str(", ");
|
||||
w.write_str(", ");
|
||||
}
|
||||
match *ty.kind {
|
||||
clean::StrippedItem(box clean::StructFieldItem(_)) => w.write_str("_"),
|
||||
@ -1297,7 +1297,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
|
||||
"<div class=\"sub-variant-field\">\
|
||||
<span id=\"{id}\" class=\"small-section-header\">\
|
||||
<a href=\"#{id}\" class=\"anchor field\">§</a>\
|
||||
<code>{f}: {t}</code>\
|
||||
<code>{f}: {t}</code>\
|
||||
</span>",
|
||||
id = id,
|
||||
f = field.name.unwrap(),
|
||||
|
@ -184,6 +184,7 @@ h4.code-header {
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
#crate-search,
|
||||
@ -642,6 +643,7 @@ pre, .rustdoc.source .example-wrap {
|
||||
.fn .where,
|
||||
.where.fmt-newline {
|
||||
display: block;
|
||||
white-space: pre-wrap;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
<script type="text/json" id="notable-traits-data">{"SomeStruct":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.SomeStruct.html\" title=\"struct doc_notable_trait::SomeStruct\">SomeStruct</a></code></h3><pre><code><span class=\"where fmt-newline\">impl <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.SomeStruct.html\" title=\"struct doc_notable_trait::SomeStruct\">SomeStruct</a></span>","Wrapper<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</code></h3><pre><code><span class=\"where fmt-newline\">impl&lt;T:&nbsp;<a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a>&gt; <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</span>"}</script>
|
||||
<script type="text/json" id="notable-traits-data">{"SomeStruct":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.SomeStruct.html\" title=\"struct doc_notable_trait::SomeStruct\">SomeStruct</a></code></h3><pre><code><span class=\"where fmt-newline\">impl <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.SomeStruct.html\" title=\"struct doc_notable_trait::SomeStruct\">SomeStruct</a></span>","Wrapper<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</code></h3><pre><code><span class=\"where fmt-newline\">impl&lt;T: <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a>&gt; <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</span>"}</script>
|
@ -1 +1 @@
|
||||
<script type="text/json" id="notable-traits-data">{"Wrapper<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</code></h3><pre><code><span class=\"where fmt-newline\">impl&lt;T:&nbsp;<a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a>&gt; <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</span>"}</script>
|
||||
<script type="text/json" id="notable-traits-data">{"Wrapper<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</code></h3><pre><code><span class=\"where fmt-newline\">impl&lt;T: <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a>&gt; <a class=\"trait\" href=\"trait.SomeTrait.html\" title=\"trait doc_notable_trait::SomeTrait\">SomeTrait</a> for <a class=\"struct\" href=\"struct.Wrapper.html\" title=\"struct doc_notable_trait::Wrapper\">Wrapper</a>&lt;T&gt;</span>"}</script>
|
@ -1,4 +1,4 @@
|
||||
<pre class="rust item-decl"><code>pub enum Cow2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <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> {
|
||||
<pre class="rust item-decl"><code>pub enum Cow2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <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> {
|
||||
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,4 @@
|
||||
<pre class="rust item-decl"><code>pub struct Struct2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <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> {
|
||||
<pre class="rust item-decl"><code>pub struct Struct2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <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> {
|
||||
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,3 +1,3 @@
|
||||
<pre class="rust item-decl"><code>pub union Union2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <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> {
|
||||
<pre class="rust item-decl"><code>pub union Union2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <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> {
|
||||
/* private fields */
|
||||
}</code></pre>
|
Loading…
x
Reference in New Issue
Block a user