about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-07-19 18:31:39 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-07-19 20:41:40 +0200
commit063ed0f9587fd9728576e200f029cb18c1eb5b12 (patch)
tree07754d6446b1e67fff6debe64555288cf0198e61
parent0cd01aac6a80735cc936f75b45e3545a5273e2ad (diff)
downloadrust-063ed0f9587fd9728576e200f029cb18c1eb5b12.tar.gz
rust-063ed0f9587fd9728576e200f029cb18c1eb5b12.zip
Improve display of trait bounds when there are more than two
-rw-r--r--src/librustdoc/html/render/print_item.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 00973865915..9256330ac7c 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -2062,16 +2062,23 @@ pub(super) fn item_path(ty: ItemType, name: &str) -> String {
 
 fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cx: &Context<'_>) -> String {
     let mut bounds = String::new();
-    if !t_bounds.is_empty() {
-        if !trait_alias {
+    if t_bounds.is_empty() {
+        return bounds;
+    }
+    let has_lots_of_bounds = t_bounds.len() > 2;
+    let inter_str = if has_lots_of_bounds { "\n    + " } else { " + " };
+    if !trait_alias {
+        if has_lots_of_bounds {
+            bounds.push_str(":\n    ");
+        } else {
             bounds.push_str(": ");
         }
-        for (i, p) in t_bounds.iter().enumerate() {
-            if i > 0 {
-                bounds.push_str(" + ");
-            }
-            bounds.push_str(&p.print(cx).to_string());
+    }
+    for (i, p) in t_bounds.iter().enumerate() {
+        if i > 0 {
+            bounds.push_str(inter_str);
         }
+        bounds.push_str(&p.print(cx).to_string());
     }
     bounds
 }