Skip to content

Commit

Permalink
rustdoc: break where clauses onto their own line if they don't have e…
Browse files Browse the repository at this point in the history
…nough room
  • Loading branch information
QuietMisdreavus committed Oct 15, 2016
1 parent 42f28d3 commit 07b27bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/librustdoc/html/format.rs
Expand Up @@ -208,7 +208,12 @@ impl<'a> fmt::Display for WhereClause<'a> {
clause.push_str("</span>");
let plain = format!("{:#}", self);
if plain.len() + pad.len() > 80 {
let padding = repeat("&nbsp;").take(pad.len() + 6).collect::<String>();
let padding = if pad.len() + 25 > 80 {
clause = clause.replace("class='where'", "class='where fmt-newline'");
repeat("&nbsp;").take(8).collect::<String>()
} else {
repeat("&nbsp;").take(pad.len() + 6).collect::<String>()
};
clause = clause.replace("<br>", &format!("<br>{}", padding));
} else {
clause = clause.replace("<br>", " ");
Expand Down
12 changes: 10 additions & 2 deletions src/librustdoc/html/static/rustdoc.css
Expand Up @@ -361,9 +361,17 @@ h4 > code, h3 > code, .invisible > code {
position: relative;
}
/* Shift "where ..." part of method or fn definition down a line */
.content .method .where, .content .fn .where { display: block; }
.content .method .where,
.content .fn .where,
.content .where.fmt-newline {
display: block;
}
/* Bit of whitespace to indent it */
.content .method .where::before, .content .fn .where::before { content: ' '; }
.content .method .where::before,
.content .fn .where::before,
.content .where.fmt-newline::before {
content: ' ';
}

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

Expand Down

0 comments on commit 07b27bb

Please sign in to comment.