Skip to content

Commit 063ed0f

Browse files
Improve display of trait bounds when there are more than two
1 parent 0cd01aa commit 063ed0f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/librustdoc/html/render/print_item.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,16 +2062,23 @@ pub(super) fn item_path(ty: ItemType, name: &str) -> String {
20622062

20632063
fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cx: &Context<'_>) -> String {
20642064
let mut bounds = String::new();
2065-
if !t_bounds.is_empty() {
2066-
if !trait_alias {
2065+
if t_bounds.is_empty() {
2066+
return bounds;
2067+
}
2068+
let has_lots_of_bounds = t_bounds.len() > 2;
2069+
let inter_str = if has_lots_of_bounds { "\n + " } else { " + " };
2070+
if !trait_alias {
2071+
if has_lots_of_bounds {
2072+
bounds.push_str(":\n ");
2073+
} else {
20672074
bounds.push_str(": ");
20682075
}
2069-
for (i, p) in t_bounds.iter().enumerate() {
2070-
if i > 0 {
2071-
bounds.push_str(" + ");
2072-
}
2073-
bounds.push_str(&p.print(cx).to_string());
2076+
}
2077+
for (i, p) in t_bounds.iter().enumerate() {
2078+
if i > 0 {
2079+
bounds.push_str(inter_str);
20742080
}
2081+
bounds.push_str(&p.print(cx).to_string());
20752082
}
20762083
bounds
20772084
}

0 commit comments

Comments
 (0)