@@ -1297,16 +1297,22 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
12971297 let variants_count = variants_iter ( ) . count ( ) ;
12981298 let has_stripped_entries = variants_len != variants_count;
12991299
1300- write_str ( w, format_args ! ( "enum {}{}" , it. name. unwrap( ) , t. generics. print( cx) ) ) ;
1301- render_enum_fields (
1300+ write_str (
13021301 w,
1303- cx,
1304- Some ( & t. generics ) ,
1305- variants,
1306- variants_count,
1307- has_stripped_entries,
1308- * is_non_exhaustive,
1309- enum_def_id,
1302+ format_args ! (
1303+ "enum {}{}{}" ,
1304+ it. name. unwrap( ) ,
1305+ t. generics. print( cx) ,
1306+ render_enum_fields(
1307+ cx,
1308+ Some ( & t. generics) ,
1309+ variants,
1310+ variants_count,
1311+ has_stripped_entries,
1312+ * is_non_exhaustive,
1313+ enum_def_id,
1314+ )
1315+ ) ,
13101316 )
13111317 } ) ;
13121318 item_variants ( w, cx, it, variants, enum_def_id) ;
@@ -1569,23 +1575,21 @@ fn item_enum(w: &mut String, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
15691575 write_str (
15701576 w,
15711577 format_args ! (
1572- "{}enum {}{}" ,
1578+ "{}enum {}{}{} " ,
15731579 visibility_print_with_space( it, cx) ,
15741580 it. name. unwrap( ) ,
15751581 e. generics. print( cx) ,
1582+ render_enum_fields(
1583+ cx,
1584+ Some ( & e. generics) ,
1585+ & e. variants,
1586+ count_variants,
1587+ e. has_stripped_entries( ) ,
1588+ it. is_non_exhaustive( ) ,
1589+ it. def_id( ) . unwrap( ) ,
1590+ ) ,
15761591 ) ,
15771592 ) ;
1578-
1579- render_enum_fields (
1580- w,
1581- cx,
1582- Some ( & e. generics ) ,
1583- & e. variants ,
1584- count_variants,
1585- e. has_stripped_entries ( ) ,
1586- it. is_non_exhaustive ( ) ,
1587- it. def_id ( ) . unwrap ( ) ,
1588- ) ;
15891593 } ) ;
15901594
15911595 write_str ( w, format_args ! ( "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ) ;
@@ -1650,90 +1654,83 @@ fn display_c_like_variant<'a, 'tcx>(
16501654 } )
16511655}
16521656
1653- fn render_enum_fields (
1654- mut w : & mut String ,
1655- cx : & Context < ' _ > ,
1656- g : Option < & clean:: Generics > ,
1657- variants : & IndexVec < VariantIdx , clean:: Item > ,
1657+ fn render_enum_fields < ' a , ' tcx > (
1658+ cx : & ' a Context < ' tcx > ,
1659+ g : Option < & ' a clean:: Generics > ,
1660+ variants : & ' a IndexVec < VariantIdx , clean:: Item > ,
16581661 count_variants : usize ,
16591662 has_stripped_entries : bool ,
16601663 is_non_exhaustive : bool ,
16611664 enum_def_id : DefId ,
1662- ) {
1663- let should_show_enum_discriminant = should_show_enum_discriminant ( cx, enum_def_id, variants) ;
1664- if let Some ( generics) = g
1665- && let Some ( where_clause) = print_where_clause ( generics, cx, 0 , Ending :: Newline )
1666- {
1667- write_str ( w, format_args ! ( "{where_clause}" ) ) ;
1668- } else {
1669- // If there wasn't a `where` clause, we add a whitespace.
1670- w. push ( ' ' )
1671- }
1672-
1673- let variants_stripped = has_stripped_entries;
1674- if count_variants == 0 && !variants_stripped {
1675- w. push_str ( "{}" ) ;
1676- } else {
1677- w. push_str ( "{\n " ) ;
1678- let toggle = should_hide_fields ( count_variants) ;
1679- if toggle {
1680- toggle_open ( & mut w, format_args ! ( "{count_variants} variants" ) ) ;
1665+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1666+ fmt:: from_fn ( move |w| {
1667+ let should_show_enum_discriminant =
1668+ should_show_enum_discriminant ( cx, enum_def_id, variants) ;
1669+ if let Some ( generics) = g
1670+ && let Some ( where_clause) = print_where_clause ( generics, cx, 0 , Ending :: Newline )
1671+ {
1672+ write ! ( w, "{where_clause}" ) ?;
1673+ } else {
1674+ // If there wasn't a `where` clause, we add a whitespace.
1675+ w. write_char ( ' ' ) ?;
16811676 }
1682- const TAB : & str = " " ;
1683- for ( index, v) in variants. iter_enumerated ( ) {
1684- if v. is_stripped ( ) {
1685- continue ;
1677+
1678+ let variants_stripped = has_stripped_entries;
1679+ if count_variants == 0 && !variants_stripped {
1680+ w. write_str ( "{}" )
1681+ } else {
1682+ w. write_str ( "{\n " ) ?;
1683+ let toggle = should_hide_fields ( count_variants) ;
1684+ if toggle {
1685+ toggle_open ( & mut * w, format_args ! ( "{count_variants} variants" ) ) ;
16861686 }
1687- w. push_str ( TAB ) ;
1688- match v. kind {
1689- clean:: VariantItem ( ref var) => match var. kind {
1690- clean:: VariantKind :: CLike => write_str (
1691- w,
1692- format_args ! (
1693- "{}" ,
1694- display_c_like_variant(
1695- cx,
1696- v,
1697- var,
1698- index,
1699- should_show_enum_discriminant,
1700- enum_def_id,
1701- )
1702- ) ,
1703- ) ,
1704- clean:: VariantKind :: Tuple ( ref s) => {
1705- write_str (
1706- w,
1707- format_args ! (
1708- "{}({})" ,
1709- v. name. unwrap( ) ,
1710- print_tuple_struct_fields( cx, s)
1711- ) ,
1712- ) ;
1713- }
1714- clean:: VariantKind :: Struct ( ref s) => {
1715- write_str (
1716- w,
1717- format_args ! (
1687+ const TAB : & str = " " ;
1688+ for ( index, v) in variants. iter_enumerated ( ) {
1689+ if v. is_stripped ( ) {
1690+ continue ;
1691+ }
1692+ w. write_str ( TAB ) ?;
1693+ match v. kind {
1694+ clean:: VariantItem ( ref var) => match var. kind {
1695+ clean:: VariantKind :: CLike => {
1696+ write ! (
1697+ w,
1698+ "{}" ,
1699+ display_c_like_variant(
1700+ cx,
1701+ v,
1702+ var,
1703+ index,
1704+ should_show_enum_discriminant,
1705+ enum_def_id,
1706+ )
1707+ ) ?;
1708+ }
1709+ clean:: VariantKind :: Tuple ( ref s) => {
1710+ write ! ( w, "{}({})" , v. name. unwrap( ) , print_tuple_struct_fields( cx, s) ) ?;
1711+ }
1712+ clean:: VariantKind :: Struct ( ref s) => {
1713+ write ! (
1714+ w,
17181715 "{}" ,
17191716 render_struct( v, None , None , & s. fields, TAB , false , cx)
1720- ) ,
1721- ) ;
1722- }
1723- } ,
1724- _ => unreachable ! ( ) ,
1717+ ) ?;
1718+ }
1719+ } ,
1720+ _ => unreachable ! ( ) ,
1721+ }
1722+ w. write_str ( ",\n " ) ?;
17251723 }
1726- w. push_str ( ",\n " ) ;
1727- }
17281724
1729- if variants_stripped && !is_non_exhaustive {
1730- w. push_str ( " <span class=\" comment\" >// some variants omitted</span>\n " ) ;
1731- }
1732- if toggle {
1733- toggle_close ( & mut w) ;
1725+ if variants_stripped && !is_non_exhaustive {
1726+ w. write_str ( " <span class=\" comment\" >// some variants omitted</span>\n " ) ?;
1727+ }
1728+ if toggle {
1729+ toggle_close ( & mut * w) ;
1730+ }
1731+ w. write_str ( "}" )
17341732 }
1735- w. push_str ( "}" ) ;
1736- }
1733+ } )
17371734}
17381735
17391736fn item_variants (
0 commit comments