@@ -62,6 +62,17 @@ struct ItemVars<'a> {
62
62
src_href : Option < & ' a str > ,
63
63
}
64
64
65
+ /// Calls `print_where_clause` and returns `true` if a `where` clause was generated.
66
+ fn print_where_clause_and_check < ' a , ' tcx : ' a > (
67
+ buffer : & mut Buffer ,
68
+ gens : & ' a clean:: Generics ,
69
+ cx : & ' a Context < ' tcx > ,
70
+ ) -> bool {
71
+ let len_before = buffer. len ( ) ;
72
+ write ! ( buffer, "{}" , print_where_clause( gens, cx, 0 , true ) ) ;
73
+ len_before != buffer. len ( )
74
+ }
75
+
65
76
pub ( super ) fn print_item (
66
77
cx : & mut Context < ' _ > ,
67
78
item : & clean:: Item ,
@@ -1152,17 +1163,21 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
1152
1163
render_attributes_in_pre ( w, it, "" ) ;
1153
1164
write ! (
1154
1165
w,
1155
- "{}enum {}{}{} " ,
1166
+ "{}enum {}{}" ,
1156
1167
it. visibility. print_with_space( it. item_id, cx) ,
1157
1168
it. name. unwrap( ) ,
1158
1169
e. generics. print( cx) ,
1159
- print_where_clause( & e. generics, cx, 0 , true ) ,
1160
1170
) ;
1171
+ if !print_where_clause_and_check ( w, & e. generics , cx) {
1172
+ // If there wasn't a `where` clause, we add a whitespace.
1173
+ w. write_str ( " " ) ;
1174
+ }
1175
+
1161
1176
let variants_stripped = e. has_stripped_entries ( ) ;
1162
1177
if count_variants == 0 && !variants_stripped {
1163
- w. write_str ( " {}" ) ;
1178
+ w. write_str ( "{}" ) ;
1164
1179
} else {
1165
- w. write_str ( " {\n " ) ;
1180
+ w. write_str ( "{\n " ) ;
1166
1181
let toggle = should_hide_fields ( count_variants) ;
1167
1182
if toggle {
1168
1183
toggle_open ( w, format_args ! ( "{} variants" , count_variants) ) ;
@@ -1643,13 +1658,21 @@ fn render_union(
1643
1658
tab : & str ,
1644
1659
cx : & Context < ' _ > ,
1645
1660
) {
1646
- write ! ( w, "{}union {}" , it. visibility. print_with_space( it. item_id, cx) , it. name. unwrap( ) ) ;
1647
- if let Some ( g) = g {
1648
- write ! ( w, "{}" , g. print( cx) ) ;
1649
- write ! ( w, "{}" , print_where_clause( g, cx, 0 , true ) ) ;
1661
+ write ! ( w, "{}union {}" , it. visibility. print_with_space( it. item_id, cx) , it. name. unwrap( ) , ) ;
1662
+
1663
+ let where_displayed = g
1664
+ . map ( |g| {
1665
+ write ! ( w, "{}" , g. print( cx) ) ;
1666
+ print_where_clause_and_check ( w, g, cx)
1667
+ } )
1668
+ . unwrap_or ( false ) ;
1669
+
1670
+ // If there wasn't a `where` clause, we add a whitespace.
1671
+ if !where_displayed {
1672
+ w. write_str ( " " ) ;
1650
1673
}
1651
1674
1652
- write ! ( w, " {{\n {}" , tab) ;
1675
+ write ! ( w, "{{\n {}" , tab) ;
1653
1676
let count_fields =
1654
1677
fields. iter ( ) . filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
1655
1678
let toggle = should_hide_fields ( count_fields) ;
@@ -1701,10 +1724,14 @@ fn render_struct(
1701
1724
}
1702
1725
match ty {
1703
1726
CtorKind :: Fictive => {
1704
- if let Some ( g) = g {
1705
- write ! ( w, "{}" , print_where_clause( g, cx, 0 , true ) , )
1727
+ let where_diplayed = g. map ( |g| print_where_clause_and_check ( w, g, cx) ) . unwrap_or ( false ) ;
1728
+
1729
+ // If there wasn't a `where` clause, we add a whitespace.
1730
+ if !where_diplayed {
1731
+ w. write_str ( " {" ) ;
1732
+ } else {
1733
+ w. write_str ( "{" ) ;
1706
1734
}
1707
- w. write_str ( " {" ) ;
1708
1735
let count_fields =
1709
1736
fields. iter ( ) . filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
1710
1737
let has_visible_fields = count_fields > 0 ;
@@ -1759,7 +1786,7 @@ fn render_struct(
1759
1786
}
1760
1787
w. write_str ( ")" ) ;
1761
1788
if let Some ( g) = g {
1762
- write ! ( w, "{}" , print_where_clause( g, cx, 0 , false ) , )
1789
+ write ! ( w, "{}" , print_where_clause( g, cx, 0 , false ) ) ;
1763
1790
}
1764
1791
// We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
1765
1792
if structhead {
@@ -1769,7 +1796,7 @@ fn render_struct(
1769
1796
CtorKind :: Const => {
1770
1797
// Needed for PhantomData.
1771
1798
if let Some ( g) = g {
1772
- write ! ( w, "{}" , print_where_clause( g, cx, 0 , false ) , )
1799
+ write ! ( w, "{}" , print_where_clause( g, cx, 0 , false ) ) ;
1773
1800
}
1774
1801
w. write_str ( ";" ) ;
1775
1802
}
0 commit comments