Skip to content

Commit

Permalink
Fix indentation for where clause in rustdoc pages
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 22, 2023
1 parent 805edb0 commit 9202caa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,19 @@ 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("\n");
br_with_padding.push('\n');

let padding_amount =
if ending == Ending::Newline { indent + 4 } else { indent + "fn where ".len() };
let where_indent = 3;
let padding_amount = if ending == Ending::Newline {
indent + 4
} else if indent == 0 {
4
} else {
indent + where_indent + "where ".len()
};

for _ in 0..padding_amount {
br_with_padding.push_str(" ");
br_with_padding.push(' ');
}
let where_preds = where_preds.to_string().replace('\n', &br_with_padding);

Expand All @@ -370,7 +376,8 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
let where_preds = where_preds.replacen(&br_with_padding, " ", 1);

let mut clause = br_with_padding;
clause.truncate(clause.len() - "where ".len());
// +1 is for `\n`.
clause.truncate(indent + 1 + where_indent);

write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
clause
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,8 @@ fn assoc_method(
w.reserve(header_len + "<a href=\"\" class=\"fn\">{".len() + "</a>".len());
write!(
w,
"{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn <a{href} class=\"fn\">{name}</a>\
{generics}{decl}{notable_traits}{where_clause}",
"{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn \
<a{href} class=\"fn\">{name}</a>{generics}{decl}{notable_traits}{where_clause}",
indent = indent_str,
vis = vis,
constness = constness,
Expand Down

0 comments on commit 9202caa

Please sign in to comment.