diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-20 19:29:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-20 19:29:00 +0200 |
| commit | 17aaba70d9c81b5f4c647a446eb995b8b9275bbb (patch) | |
| tree | ff149fd2fb005113308a9154cef73e96cc280d7f /src/librustdoc/html | |
| parent | ae28d5c9e729fe9216380de7d79292207c5e479a (diff) | |
| parent | eec3c3db88dff8ed429ca2f584138f252c60d4fe (diff) | |
| download | rust-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:  After this PR:  r? `@notriddle`
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 21 |
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 } |
