Skip to content

Commit 9202caa

Browse files
Fix indentation for where clause in rustdoc pages
1 parent 805edb0 commit 9202caa

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/librustdoc/html/format.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,19 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
347347
}
348348
} else {
349349
let mut br_with_padding = String::with_capacity(6 * indent + 28);
350-
br_with_padding.push_str("\n");
350+
br_with_padding.push('\n');
351351

352-
let padding_amount =
353-
if ending == Ending::Newline { indent + 4 } else { indent + "fn where ".len() };
352+
let where_indent = 3;
353+
let padding_amount = if ending == Ending::Newline {
354+
indent + 4
355+
} else if indent == 0 {
356+
4
357+
} else {
358+
indent + where_indent + "where ".len()
359+
};
354360

355361
for _ in 0..padding_amount {
356-
br_with_padding.push_str(" ");
362+
br_with_padding.push(' ');
357363
}
358364
let where_preds = where_preds.to_string().replace('\n', &br_with_padding);
359365

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

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

375382
write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
376383
clause

src/librustdoc/html/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ fn assoc_method(
859859
w.reserve(header_len + "<a href=\"\" class=\"fn\">{".len() + "</a>".len());
860860
write!(
861861
w,
862-
"{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn <a{href} class=\"fn\">{name}</a>\
863-
{generics}{decl}{notable_traits}{where_clause}",
862+
"{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn \
863+
<a{href} class=\"fn\">{name}</a>{generics}{decl}{notable_traits}{where_clause}",
864864
indent = indent_str,
865865
vis = vis,
866866
constness = constness,

0 commit comments

Comments
 (0)