rustdoc: format bare functions like rustfmt
see commit 2a274e72
for details
This commit is contained in:
parent
2a274e720f
commit
fb442a7e27
2 changed files with 37 additions and 32 deletions
|
@ -621,17 +621,19 @@ impl fmt::Display for clean::Type {
|
||||||
clean::Generic(_) =>
|
clean::Generic(_) =>
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
primitive_link(f, PrimitiveType::Slice,
|
primitive_link(f, PrimitiveType::Slice,
|
||||||
&format!("&{}{}[{:#}]", lt, m, **bt))
|
&format!("&{}{}[{:#}]", lt, m, **bt))
|
||||||
} else {
|
} else {
|
||||||
primitive_link(f, PrimitiveType::Slice,
|
primitive_link(f, PrimitiveType::Slice,
|
||||||
&format!("&{}{}[{}]", lt, m, **bt))
|
&format!("&{}{}[{}]", lt, m, **bt))
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
primitive_link(f, PrimitiveType::Slice,
|
|
||||||
&format!("&{}{}[", lt, m))?;
|
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
|
primitive_link(f, PrimitiveType::Slice,
|
||||||
|
&format!("&{}{}[", lt, m))?;
|
||||||
write!(f, "{:#}", **bt)?;
|
write!(f, "{:#}", **bt)?;
|
||||||
} else {
|
} else {
|
||||||
|
primitive_link(f, PrimitiveType::Slice,
|
||||||
|
&format!("&{}{}[", lt, m))?;
|
||||||
write!(f, "{}", **bt)?;
|
write!(f, "{}", **bt)?;
|
||||||
}
|
}
|
||||||
primitive_link(f, PrimitiveType::Slice, "]")
|
primitive_link(f, PrimitiveType::Slice, "]")
|
||||||
|
@ -640,7 +642,7 @@ impl fmt::Display for clean::Type {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
write!(f, "&{}{}{:#}", lt, m, **ty)
|
write!(f, "&{}{}{:#}", lt, m, **ty)
|
||||||
} else {
|
} else {
|
||||||
write!(f, "&{}{}{}", lt, m, **ty)
|
write!(f, "&{}{}{}", lt, m, **ty)
|
||||||
}
|
}
|
||||||
|
@ -757,7 +759,6 @@ pub fn fmt_impl_for_trait_page(i: &clean::Impl, f: &mut fmt::Formatter) -> fmt::
|
||||||
impl fmt::Display for clean::Arguments {
|
impl fmt::Display for clean::Arguments {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for (i, input) in self.values.iter().enumerate() {
|
for (i, input) in self.values.iter().enumerate() {
|
||||||
write!(f, "\n ")?;
|
|
||||||
if !input.name.is_empty() {
|
if !input.name.is_empty() {
|
||||||
write!(f, "{}: ", input.name)?;
|
write!(f, "{}: ", input.name)?;
|
||||||
}
|
}
|
||||||
|
@ -766,10 +767,7 @@ impl fmt::Display for clean::Arguments {
|
||||||
} else {
|
} else {
|
||||||
write!(f, "{}", input.type_)?;
|
write!(f, "{}", input.type_)?;
|
||||||
}
|
}
|
||||||
if i + 1 < self.values.len() { write!(f, ",")?; }
|
if i + 1 < self.values.len() { write!(f, ", ")?; }
|
||||||
}
|
|
||||||
if !self.values.is_empty() {
|
|
||||||
write!(f, "\n")?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -819,14 +817,12 @@ impl<'a> fmt::Display for Method<'a> {
|
||||||
args_plain.push_str("self");
|
args_plain.push_str("self");
|
||||||
}
|
}
|
||||||
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
clean::SelfBorrowed(Some(ref lt), mtbl) => {
|
||||||
let arg = format!("{}{} {}self", amp, *lt, MutableSpace(mtbl));
|
args.push_str(&format!("{}{} {}self", amp, *lt, MutableSpace(mtbl)));
|
||||||
args.push_str(&arg);
|
args_plain.push_str(&format!("&{} {}self", *lt, MutableSpace(mtbl)));
|
||||||
args_plain.push_str(&arg);
|
|
||||||
}
|
}
|
||||||
clean::SelfBorrowed(None, mtbl) => {
|
clean::SelfBorrowed(None, mtbl) => {
|
||||||
let arg = format!("{}{}self", amp, MutableSpace(mtbl));
|
args.push_str(&format!("{}{}self", amp, MutableSpace(mtbl)));
|
||||||
args.push_str(&arg);
|
args_plain.push_str(&format!("&{}self", MutableSpace(mtbl)));
|
||||||
args_plain.push_str(&arg);
|
|
||||||
}
|
}
|
||||||
clean::SelfExplicit(ref typ) => {
|
clean::SelfExplicit(ref typ) => {
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
|
@ -839,13 +835,14 @@ impl<'a> fmt::Display for Method<'a> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
args.push_str("\n ");
|
args.push_str("<br> ");
|
||||||
args_plain.push_str("\n ");
|
args_plain.push_str(" ");
|
||||||
}
|
}
|
||||||
if !input.name.is_empty() {
|
if !input.name.is_empty() {
|
||||||
args.push_str(&format!("{}: ", input.name));
|
args.push_str(&format!("{}: ", input.name));
|
||||||
args_plain.push_str(&format!("{}: ", input.name));
|
args_plain.push_str(&format!("{}: ", input.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.alternate() {
|
if f.alternate() {
|
||||||
args.push_str(&format!("{:#}", input.type_));
|
args.push_str(&format!("{:#}", input.type_));
|
||||||
} else {
|
} else {
|
||||||
|
@ -859,6 +856,11 @@ impl<'a> fmt::Display for Method<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if decl.variadic {
|
||||||
|
args.push_str(",<br> ...");
|
||||||
|
args_plain.push_str(", ...");
|
||||||
|
}
|
||||||
|
|
||||||
let arrow_plain = format!("{:#}", decl.output);
|
let arrow_plain = format!("{:#}", decl.output);
|
||||||
let arrow = if f.alternate() {
|
let arrow = if f.alternate() {
|
||||||
format!("{:#}", decl.output)
|
format!("{:#}", decl.output)
|
||||||
|
@ -870,17 +872,20 @@ impl<'a> fmt::Display for Method<'a> {
|
||||||
let plain: String;
|
let plain: String;
|
||||||
if arrow.is_empty() {
|
if arrow.is_empty() {
|
||||||
output = format!("({})", args);
|
output = format!("({})", args);
|
||||||
plain = format!("({})", args_plain);
|
plain = format!("{}({})", indent.replace(" ", " "), args_plain);
|
||||||
} else {
|
} else {
|
||||||
output = format!("({args})\n{arrow}", args = args, arrow = arrow);
|
output = format!("({args})<br>{arrow}", args = args, arrow = arrow);
|
||||||
plain = format!("({args})\n{arrow}", args = args_plain, arrow = arrow_plain);
|
plain = format!("{indent}({args}){arrow}",
|
||||||
|
indent = indent.replace(" ", " "),
|
||||||
|
args = args_plain,
|
||||||
|
arrow = arrow_plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if plain.replace("\n", "").len() > 80 {
|
if plain.len() > 80 {
|
||||||
let pad = format!("\n{}", indent);
|
let pad = format!("<br>{}", indent);
|
||||||
output = output.replace("\n", &pad);
|
output = output.replace("<br>", &pad);
|
||||||
} else {
|
} else {
|
||||||
output = output.replace("\n", "");
|
output = output.replace("<br>", "");
|
||||||
}
|
}
|
||||||
write!(f, "{}", output)
|
write!(f, "{}", output)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1975,13 +1975,13 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||||
UnstableFeatures::Allow => f.constness,
|
UnstableFeatures::Allow => f.constness,
|
||||||
_ => hir::Constness::NotConst
|
_ => hir::Constness::NotConst
|
||||||
};
|
};
|
||||||
let prefix = format!("{vis}{constness}{unsafety}{abi:#}fn {name}{generics:#}",
|
let prefix = format!("{}{}{}{:#}fn {}{:#}",
|
||||||
vis = VisSpace(&it.visibility),
|
VisSpace(&it.visibility),
|
||||||
constness = ConstnessSpace(vis_constness),
|
ConstnessSpace(vis_constness),
|
||||||
unsafety = UnsafetySpace(f.unsafety),
|
UnsafetySpace(f.unsafety),
|
||||||
abi = AbiSpace(f.abi),
|
AbiSpace(f.abi),
|
||||||
name = it.name.as_ref().unwrap(),
|
it.name.as_ref().unwrap(),
|
||||||
generics = f.generics)?;
|
f.generics);
|
||||||
let indent = repeat(" ").take(prefix.len()).collect::<String>();
|
let indent = repeat(" ").take(prefix.len()).collect::<String>();
|
||||||
write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
|
write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
|
||||||
{name}{generics}{decl}{where_clause}</pre>",
|
{name}{generics}{decl}{where_clause}</pre>",
|
||||||
|
@ -1992,7 +1992,7 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||||
name = it.name.as_ref().unwrap(),
|
name = it.name.as_ref().unwrap(),
|
||||||
generics = f.generics,
|
generics = f.generics,
|
||||||
where_clause = WhereClause(&f.generics),
|
where_clause = WhereClause(&f.generics),
|
||||||
decl = f.decl)?;
|
decl = Method(&f.decl, &indent))?;
|
||||||
document(w, cx, it)
|
document(w, cx, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue