From 07b27bb34c4ce32152369d202cac7a4e0c9878af Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Sat, 15 Oct 2016 10:29:47 -0500 Subject: [PATCH] rustdoc: break where clauses onto their own line if they don't have enough room --- src/librustdoc/html/format.rs | 7 ++++++- src/librustdoc/html/static/rustdoc.css | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 3b2f2430993a1..5fb99a2031fb5 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -208,7 +208,12 @@ impl<'a> fmt::Display for WhereClause<'a> { clause.push_str(""); let plain = format!("{:#}", self); if plain.len() + pad.len() > 80 { - let padding = repeat(" ").take(pad.len() + 6).collect::(); + let padding = if pad.len() + 25 > 80 { + clause = clause.replace("class='where'", "class='where fmt-newline'"); + repeat(" ").take(8).collect::() + } else { + repeat(" ").take(pad.len() + 6).collect::() + }; clause = clause.replace("
", &format!("
{}", padding)); } else { clause = clause.replace("
", " "); diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index f8133ea49ceba..3b6ffa4a462f6 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -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; }