@@ -245,7 +245,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
245
245
clean:: TraitItem ( ref t) => write_str ( buf, format_args ! ( "{}" , item_trait( cx, item, t) ) ) ,
246
246
clean:: StructItem ( ref s) => write_str ( buf, format_args ! ( "{}" , item_struct( cx, item, s) ) ) ,
247
247
clean:: UnionItem ( ref s) => write_str ( buf, format_args ! ( "{}" , item_union( cx, item, s) ) ) ,
248
- clean:: EnumItem ( ref e) => item_enum ( buf, cx, item, e) ,
248
+ clean:: EnumItem ( ref e) => write_str ( buf, format_args ! ( "{}" , item_enum ( cx, item, e) ) ) ,
249
249
clean:: TypeAliasItem ( ref t) => item_type_alias ( buf, cx, item, t) ,
250
250
clean:: MacroItem ( ref m) => item_macro ( buf, cx, item, m) ,
251
251
clean:: ProcMacroItem ( ref m) => item_proc_macro ( buf, cx, item, m) ,
@@ -1315,7 +1315,7 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
1315
1315
) ,
1316
1316
)
1317
1317
} ) ;
1318
- item_variants ( w, cx, it, variants, enum_def_id) ;
1318
+ write_str ( w, format_args ! ( "{}" , item_variants ( cx, it, variants, enum_def_id) ) ) ;
1319
1319
}
1320
1320
clean:: TypeAliasInnerType :: Union { fields } => {
1321
1321
wrap_item ( w, |w| {
@@ -1568,13 +1568,17 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
1568
1568
} )
1569
1569
}
1570
1570
1571
- fn item_enum ( w : & mut String , cx : & Context < ' _ > , it : & clean:: Item , e : & clean:: Enum ) {
1572
- let count_variants = e. variants ( ) . count ( ) ;
1573
- wrap_item ( w, |w| {
1574
- render_attributes_in_code ( w, it, cx) ;
1575
- write_str (
1576
- w,
1577
- format_args ! (
1571
+ fn item_enum < ' a , ' tcx > (
1572
+ cx : & ' a Context < ' tcx > ,
1573
+ it : & ' a clean:: Item ,
1574
+ e : & ' a clean:: Enum ,
1575
+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1576
+ fmt:: from_fn ( |w| {
1577
+ let count_variants = e. variants ( ) . count ( ) ;
1578
+ wrap_item ( w, |w| {
1579
+ render_attributes_in_code ( w, it, cx) ;
1580
+ write ! (
1581
+ w,
1578
1582
"{}enum {}{}{}" ,
1579
1583
visibility_print_with_space( it, cx) ,
1580
1584
it. name. unwrap( ) ,
@@ -1588,18 +1592,22 @@ fn item_enum(w: &mut String, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
1588
1592
it. is_non_exhaustive( ) ,
1589
1593
it. def_id( ) . unwrap( ) ,
1590
1594
) ,
1591
- ) ,
1592
- ) ;
1593
- } ) ;
1595
+ )
1596
+ } ) ?;
1594
1597
1595
- write_str ( w, format_args ! ( "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ) ;
1598
+ write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ? ;
1596
1599
1597
- if count_variants != 0 {
1598
- item_variants ( w, cx, it, & e. variants , it. def_id ( ) . unwrap ( ) ) ;
1599
- }
1600
- let def_id = it. item_id . expect_def_id ( ) ;
1601
- write_str ( w, format_args ! ( "{}" , render_assoc_items( cx, it, def_id, AssocItemRender :: All ) ) ) ;
1602
- write_str ( w, format_args ! ( "{}" , document_type_layout( cx, def_id) ) ) ;
1600
+ if count_variants != 0 {
1601
+ write ! ( w, "{}" , item_variants( cx, it, & e. variants, it. def_id( ) . unwrap( ) ) ) ?;
1602
+ }
1603
+ let def_id = it. item_id . expect_def_id ( ) ;
1604
+ write ! (
1605
+ w,
1606
+ "{}{}" ,
1607
+ render_assoc_items( cx, it, def_id, AssocItemRender :: All ) ,
1608
+ document_type_layout( cx, def_id)
1609
+ )
1610
+ } )
1603
1611
}
1604
1612
1605
1613
/// It'll return false if any variant is not a C-like variant. Otherwise it'll return true if at
@@ -1733,36 +1741,34 @@ fn render_enum_fields<'a, 'tcx>(
1733
1741
} )
1734
1742
}
1735
1743
1736
- fn item_variants (
1737
- w : & mut String ,
1738
- cx : & Context < ' _ > ,
1739
- it : & clean:: Item ,
1740
- variants : & IndexVec < VariantIdx , clean:: Item > ,
1744
+ fn item_variants < ' a , ' tcx > (
1745
+ cx : & ' a Context < ' tcx > ,
1746
+ it : & ' a clean:: Item ,
1747
+ variants : & ' a IndexVec < VariantIdx , clean:: Item > ,
1741
1748
enum_def_id : DefId ,
1742
- ) {
1743
- let tcx = cx . tcx ( ) ;
1744
- write_str (
1745
- w ,
1746
- format_args ! (
1749
+ ) -> impl fmt :: Display + ' a + Captures < ' tcx > {
1750
+ fmt :: from_fn ( move |w| {
1751
+ let tcx = cx . tcx ( ) ;
1752
+ write ! (
1753
+ w ,
1747
1754
"{}" ,
1748
1755
write_section_heading(
1749
1756
& format!( "Variants{}" , document_non_exhaustive_header( it) ) ,
1750
1757
"variants" ,
1751
1758
Some ( "variants" ) ,
1752
1759
format!( "{}<div class=\" variants\" >" , document_non_exhaustive( it) ) ,
1753
- )
1754
- ) ,
1755
- ) ;
1760
+ ) ,
1761
+ ) ?;
1756
1762
1757
- let should_show_enum_discriminant = should_show_enum_discriminant ( cx , enum_def_id , variants ) ;
1758
- for ( index , variant ) in variants. iter_enumerated ( ) {
1759
- if variant. is_stripped ( ) {
1760
- continue ;
1761
- }
1762
- let id = cx . derive_id ( format ! ( "{}.{}" , ItemType :: Variant , variant . name . unwrap ( ) ) ) ;
1763
- write_str (
1764
- w ,
1765
- format_args ! (
1763
+ let should_show_enum_discriminant =
1764
+ should_show_enum_discriminant ( cx , enum_def_id , variants) ;
1765
+ for ( index , variant) in variants . iter_enumerated ( ) {
1766
+ if variant . is_stripped ( ) {
1767
+ continue ;
1768
+ }
1769
+ let id = cx . derive_id ( format ! ( "{}.{}" , ItemType :: Variant , variant . name . unwrap ( ) ) ) ;
1770
+ write ! (
1771
+ w ,
1766
1772
"<section id=\" {id}\" class=\" variant\" >\
1767
1773
<a href=\" #{id}\" class=\" anchor\" >§</a>\
1768
1774
{}\
@@ -1773,14 +1779,12 @@ fn item_variants(
1773
1779
" rightside" ,
1774
1780
)
1775
1781
. maybe_display( )
1776
- ) ,
1777
- ) ;
1778
- if let clean:: VariantItem ( ref var) = variant. kind
1779
- && let clean:: VariantKind :: CLike = var. kind
1780
- {
1781
- write_str (
1782
- w,
1783
- format_args ! (
1782
+ ) ?;
1783
+ if let clean:: VariantItem ( ref var) = variant. kind
1784
+ && let clean:: VariantKind :: CLike = var. kind
1785
+ {
1786
+ write ! (
1787
+ w,
1784
1788
"{}" ,
1785
1789
display_c_like_variant(
1786
1790
cx,
@@ -1790,90 +1794,82 @@ fn item_variants(
1790
1794
should_show_enum_discriminant,
1791
1795
enum_def_id,
1792
1796
)
1793
- ) ,
1794
- ) ;
1795
- } else {
1796
- w. push_str ( variant. name . unwrap ( ) . as_str ( ) ) ;
1797
- }
1797
+ ) ?;
1798
+ } else {
1799
+ w. write_str ( variant. name . unwrap ( ) . as_str ( ) ) ?;
1800
+ }
1798
1801
1799
- let clean:: VariantItem ( variant_data) = & variant. kind else { unreachable ! ( ) } ;
1802
+ let clean:: VariantItem ( variant_data) = & variant. kind else { unreachable ! ( ) } ;
1800
1803
1801
- if let clean:: VariantKind :: Tuple ( ref s) = variant_data. kind {
1802
- write_str ( w, format_args ! ( "({})" , print_tuple_struct_fields( cx, s) ) ) ;
1803
- }
1804
- w . push_str ( "</h3></section>" ) ;
1804
+ if let clean:: VariantKind :: Tuple ( ref s) = variant_data. kind {
1805
+ write ! ( w, "({})" , print_tuple_struct_fields( cx, s) ) ? ;
1806
+ }
1807
+ w . write_str ( "</h3></section>" ) ? ;
1805
1808
1806
- write_str ( w, format_args ! ( "{}" , document( cx, variant, Some ( it) , HeadingOffset :: H4 ) ) ) ;
1809
+ write ! ( w, "{}" , document( cx, variant, Some ( it) , HeadingOffset :: H4 ) ) ? ;
1807
1810
1808
- let heading_and_fields = match & variant_data. kind {
1809
- clean:: VariantKind :: Struct ( s) => {
1810
- // If there is no field to display, no need to add the heading.
1811
- if s. fields . iter ( ) . any ( |f| !f. is_doc_hidden ( ) ) {
1812
- Some ( ( "Fields" , & s. fields ) )
1813
- } else {
1814
- None
1811
+ let heading_and_fields = match & variant_data. kind {
1812
+ clean:: VariantKind :: Struct ( s) => {
1813
+ // If there is no field to display, no need to add the heading.
1814
+ if s. fields . iter ( ) . any ( |f| !f. is_doc_hidden ( ) ) {
1815
+ Some ( ( "Fields" , & s. fields ) )
1816
+ } else {
1817
+ None
1818
+ }
1815
1819
}
1816
- }
1817
- clean :: VariantKind :: Tuple ( fields) => {
1818
- // Documentation on tuple variant fields is rare, so to reduce noise we only emit
1819
- // the section if at least one field is documented.
1820
- if fields . iter ( ) . any ( |f| !f . doc_value ( ) . is_empty ( ) ) {
1821
- Some ( ( "Tuple Fields" , fields ) )
1822
- } else {
1823
- None
1820
+ clean :: VariantKind :: Tuple ( fields ) => {
1821
+ // Documentation on tuple variant fields is rare, so to reduce noise we only emit
1822
+ // the section if at least one field is documented.
1823
+ if fields . iter ( ) . any ( |f| !f . doc_value ( ) . is_empty ( ) ) {
1824
+ Some ( ( "Tuple Fields" , fields ) )
1825
+ } else {
1826
+ None
1827
+ }
1824
1828
}
1825
- }
1826
- clean:: VariantKind :: CLike => None ,
1827
- } ;
1829
+ clean:: VariantKind :: CLike => None ,
1830
+ } ;
1828
1831
1829
- if let Some ( ( heading, fields) ) = heading_and_fields {
1830
- let variant_id =
1831
- cx. derive_id ( format ! ( "{}.{}.fields" , ItemType :: Variant , variant. name. unwrap( ) ) ) ;
1832
- write_str (
1833
- w,
1834
- format_args ! (
1832
+ if let Some ( ( heading, fields) ) = heading_and_fields {
1833
+ let variant_id =
1834
+ cx. derive_id ( format ! ( "{}.{}.fields" , ItemType :: Variant , variant. name. unwrap( ) ) ) ;
1835
+ write ! (
1836
+ w,
1835
1837
"<div class=\" sub-variant\" id=\" {variant_id}\" >\
1836
1838
<h4>{heading}</h4>\
1837
1839
{}",
1838
1840
document_non_exhaustive( variant)
1839
- ) ,
1840
- ) ;
1841
- for field in fields {
1842
- match field. kind {
1843
- clean:: StrippedItem ( box clean:: StructFieldItem ( _) ) => { }
1844
- clean:: StructFieldItem ( ref ty) => {
1845
- let id = cx. derive_id ( format ! (
1846
- "variant.{}.field.{}" ,
1847
- variant. name. unwrap( ) ,
1848
- field. name. unwrap( )
1849
- ) ) ;
1850
- write_str (
1851
- w,
1852
- format_args ! (
1841
+ ) ?;
1842
+ for field in fields {
1843
+ match field. kind {
1844
+ clean:: StrippedItem ( box clean:: StructFieldItem ( _) ) => { }
1845
+ clean:: StructFieldItem ( ref ty) => {
1846
+ let id = cx. derive_id ( format ! (
1847
+ "variant.{}.field.{}" ,
1848
+ variant. name. unwrap( ) ,
1849
+ field. name. unwrap( )
1850
+ ) ) ;
1851
+ write ! (
1852
+ w,
1853
1853
"<div class=\" sub-variant-field\" >\
1854
1854
<span id=\" {id}\" class=\" section-header\" >\
1855
1855
<a href=\" #{id}\" class=\" anchor field\" >§</a>\
1856
1856
<code>{f}: {t}</code>\
1857
- </span>",
1857
+ </span>\
1858
+ {doc}\
1859
+ </div>",
1858
1860
f = field. name. unwrap( ) ,
1859
1861
t = ty. print( cx) ,
1860
- ) ,
1861
- ) ;
1862
- write_str (
1863
- w,
1864
- format_args ! (
1865
- "{}</div>" ,
1866
- document( cx, field, Some ( variant) , HeadingOffset :: H5 ) ,
1867
- ) ,
1868
- ) ;
1862
+ doc = document( cx, field, Some ( variant) , HeadingOffset :: H5 ) ,
1863
+ ) ?;
1864
+ }
1865
+ _ => unreachable ! ( ) ,
1869
1866
}
1870
- _ => unreachable ! ( ) ,
1871
1867
}
1868
+ w. write_str ( "</div>" ) ?;
1872
1869
}
1873
- w. push_str ( "</div>" ) ;
1874
1870
}
1875
- }
1876
- write_str ( w , format_args ! ( "</div>" ) ) ;
1871
+ w . write_str ( "</div>" )
1872
+ } )
1877
1873
}
1878
1874
1879
1875
fn item_macro ( w : & mut String , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Macro ) {
0 commit comments