Skip to content

Commit 07b27bb

Browse files
author
QuietMisdreavus
committed
rustdoc: break where clauses onto their own line if they don't have enough room
1 parent 42f28d3 commit 07b27bb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/librustdoc/html/format.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ impl<'a> fmt::Display for WhereClause<'a> {
208208
clause.push_str("</span>");
209209
let plain = format!("{:#}", self);
210210
if plain.len() + pad.len() > 80 {
211-
let padding = repeat("&nbsp;").take(pad.len() + 6).collect::<String>();
211+
let padding = if pad.len() + 25 > 80 {
212+
clause = clause.replace("class='where'", "class='where fmt-newline'");
213+
repeat("&nbsp;").take(8).collect::<String>()
214+
} else {
215+
repeat("&nbsp;").take(pad.len() + 6).collect::<String>()
216+
};
212217
clause = clause.replace("<br>", &format!("<br>{}", padding));
213218
} else {
214219
clause = clause.replace("<br>", " ");

src/librustdoc/html/static/rustdoc.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,17 @@ h4 > code, h3 > code, .invisible > code {
361361
position: relative;
362362
}
363363
/* Shift "where ..." part of method or fn definition down a line */
364-
.content .method .where, .content .fn .where { display: block; }
364+
.content .method .where,
365+
.content .fn .where,
366+
.content .where.fmt-newline {
367+
display: block;
368+
}
365369
/* Bit of whitespace to indent it */
366-
.content .method .where::before, .content .fn .where::before { content: ' '; }
370+
.content .method .where::before,
371+
.content .fn .where::before,
372+
.content .where.fmt-newline::before {
373+
content: ' ';
374+
}
367375

368376
.content .methods > div { margin-left: 40px; }
369377

0 commit comments

Comments
 (0)