about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-07-20 19:29:00 +0200
committerGitHub <noreply@github.com>2024-07-20 19:29:00 +0200
commit17aaba70d9c81b5f4c647a446eb995b8b9275bbb (patch)
treeff149fd2fb005113308a9154cef73e96cc280d7f /src/librustdoc/html
parentae28d5c9e729fe9216380de7d79292207c5e479a (diff)
parenteec3c3db88dff8ed429ca2f584138f252c60d4fe (diff)
downloadrust-17aaba70d9c81b5f4c647a446eb995b8b9275bbb.tar.gz
rust-17aaba70d9c81b5f4c647a446eb995b8b9275bbb.zip
Rollup merge of #127975 - GuillaumeGomez:fix-trait-bounds-display, r=notriddle
Fix trait bounds display

Fixes https://github.com/rust-lang/rust/issues/127398.

I took a simple rule: if there are more than two bounds, we display them like rustfmt.

Before this PR:

![Screenshot from 2024-07-19 17-38-59](https://github.com/user-attachments/assets/4162b57e-7ebb-48f9-a3a1-25e443c140cb)

After this PR:

![Screenshot from 2024-07-19 17-39-09](https://github.com/user-attachments/assets/a3ba22dd-5f34-45d0-ad9d-0cdf89dc509c)

r? `@notriddle`
Diffstat (limited to 'src/librustdoc/html')
-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
 }