about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-05 14:01:49 +0000
committerbors <bors@rust-lang.org>2023-02-05 14:01:49 +0000
commit319b88c463fe6f51bb6badbbd3bb97252a60f3a5 (patch)
tree6ebac807802fa2458d2f47c2c12fb1e62944e764 /src
parent7f97aeaf73047268299ab55288b3dd886130be47 (diff)
parent71a147df1f6fea8f023c5054e0e7591dfb2aa5ae (diff)
Auto merge of #102842 - rol1510:issue-85566-fix, r=notriddle
rustdoc: change trait bound formatting

Fixes #85566

Before
<img width="268" alt="image" src="https://user-images.githubusercontent.com/29011024/208326689-cc9b4bae-529c-473c-81e2-fc5ddb738f07.png">

Now
<img width="268" alt="image" src="https://user-images.githubusercontent.com/29011024/216216918-d7923787-3e3b-486d-9735-4cecd2988dba.png">
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/format.rs12
-rw-r--r--src/librustdoc/html/render/print_item.rs20
-rw-r--r--src/librustdoc/html/static/css/rustdoc.css1
3 files changed, 21 insertions, 12 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 74cdf9b9b79..a59cfbea885 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -353,7 +353,11 @@ 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("<br>");
-            for _ in 0..indent + 4 {
+
+            let padding_amout =
+                if ending == Ending::Newline { indent + 4 } else { indent + "fn where ".len() };
+
+            for _ in 0..padding_amout {
                 br_with_padding.push_str(" ");
             }
             let where_preds = where_preds.to_string().replace("<br>", &br_with_padding);
@@ -367,8 +371,12 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
                 if indent == 0 {
                     format!("<br><span class=\"where\">where{where_preds}</span>")
                 } else {
+                    // put the first one on the same line as the 'where' keyword
+                    let where_preds = where_preds.replacen(&br_with_padding, " ", 1);
+
                     let mut clause = br_with_padding;
-                    clause.truncate(clause.len() - 4);
+                    clause.truncate(clause.len() - "where ".len());
+
                     write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
                     clause
                 }
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 9a7a08ab806..c2d24e51484 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -645,6 +645,10 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
             if count_consts != 0 && count_methods != 0 {
                 w.write_str("\n");
             }
+
+            if !required_methods.is_empty() {
+                write!(w, "    // Required method{}\n", pluralize(required_methods.len()));
+            }
             for (pos, m) in required_methods.iter().enumerate() {
                 render_assoc_item(
                     w,
@@ -663,6 +667,10 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
             if !required_methods.is_empty() && !provided_methods.is_empty() {
                 w.write_str("\n");
             }
+
+            if !provided_methods.is_empty() {
+                write!(w, "    // Provided method{}\n", pluralize(provided_methods.len()));
+            }
             for (pos, m) in provided_methods.iter().enumerate() {
                 render_assoc_item(
                     w,
@@ -672,16 +680,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
                     cx,
                     RenderMode::Normal,
                 );
-                match *m.kind {
-                    clean::MethodItem(ref inner, _)
-                        if !inner.generics.where_predicates.is_empty() =>
-                    {
-                        w.write_str(",\n    { ... }\n");
-                    }
-                    _ => {
-                        w.write_str(" { ... }\n");
-                    }
-                }
+
+                w.write_str(" { ... }\n");
 
                 if pos < provided_methods.len() - 1 {
                     w.write_str("<span class=\"item-spacer\"></span>");
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index a1e91118303..2a9548712f0 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -1176,6 +1176,7 @@ a.test-arrow:hover {
 .item-spacer {
 	width: 100%;
 	height: 12px;
+	display: block;
 }
 
 .out-of-band > span.since {