X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustdoc%2Fhtml%2Fformat.rs;h=8a7a8ea5fd1f268a69c6e7f39eb319030f032896;hb=8307fd7901c9832e7b22ee5139efe6f7f2d291b3;hp=33404a76835975da4e656f3f8bff6f5952116202;hpb=eb5e63e3f0144d145e85bc0677ea49b97b491896;p=rust.git
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 33404a76835..8a7a8ea5fd1 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -208,7 +208,7 @@ pub(crate) fn print<'a, 'tcx: 'a>(
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 @@ pub(crate) fn print<'a, 'tcx: 'a>(
if f.alternate() {
write!(f, " = {:#}", ty.print(cx))?;
} else {
- write!(f, " = {}", ty.print(cx))?;
+ write!(f, " = {}", ty.print(cx))?;
}
}
@@ -226,14 +226,14 @@ pub(crate) fn print<'a, 'tcx: 'a>(
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)?;
}
}
@@ -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,23 +352,31 @@ 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("
");
- for _ in 0..indent + 4 {
- 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() };
+
+ 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));
+ 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);
+
let mut clause = br_with_padding;
- clause.truncate(clause.len() - 4 * " ".len());
+ clause.truncate(clause.len() - "where ".len());
+
write!(clause, "where{where_preds}")?;
clause
}
@@ -1307,7 +1315,8 @@ pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
/// * `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>( @@ -1355,7 +1364,7 @@ fn inner_full_print( } } else { if i > 0 { - args.push_str("
"); + args.push_str("\n"); } if input.is_const { args.push_str("const "); @@ -1381,7 +1390,7 @@ fn inner_full_print( let mut args = args.into_inner(); if self.c_variadic { - args.push_str(",
..."); + args.push_str(",\n ..."); args_plain.push_str(", ..."); } @@ -1391,24 +1400,20 @@ fn inner_full_print( 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) } } @@ -1611,7 +1616,7 @@ pub(crate) fn print<'a, 'tcx: 'a>( 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))?; } } }