@@ -43,6 +43,7 @@ use std::iter::Peekable;
43
43
use std:: path:: PathBuf ;
44
44
use std:: { fs, str} ;
45
45
46
+ use itertools:: Either ;
46
47
use rinja:: Template ;
47
48
use rustc_attr_parsing:: {
48
49
ConstStability , DeprecatedSince , Deprecation , RustcVersion , StabilityLevel , StableSince ,
@@ -1647,8 +1648,8 @@ fn render_impl(
1647
1648
// `containing_item` is used for rendering stability info. If the parent is a trait impl,
1648
1649
// `containing_item` will the grandparent, since trait impls can't have stability attached.
1649
1650
fn doc_impl_item (
1650
- boring : & mut String ,
1651
- interesting : & mut String ,
1651
+ boring : impl fmt :: Write ,
1652
+ interesting : impl fmt :: Write ,
1652
1653
cx : & Context < ' _ > ,
1653
1654
item : & clean:: Item ,
1654
1655
parent : & clean:: Item ,
@@ -1657,7 +1658,7 @@ fn render_impl(
1657
1658
is_default_item : bool ,
1658
1659
trait_ : Option < & clean:: Trait > ,
1659
1660
rendering_params : ImplRenderingParameters ,
1660
- ) {
1661
+ ) -> fmt :: Result {
1661
1662
let item_type = item. type_ ( ) ;
1662
1663
let name = item. name . as_ref ( ) . unwrap ( ) ;
1663
1664
@@ -1732,15 +1733,16 @@ fn render_impl(
1732
1733
) ;
1733
1734
}
1734
1735
}
1735
- let w = if short_documented && trait_. is_some ( ) { interesting } else { boring } ;
1736
+ let mut w = if short_documented && trait_. is_some ( ) {
1737
+ Either :: Left ( interesting)
1738
+ } else {
1739
+ Either :: Right ( boring)
1740
+ } ;
1736
1741
1737
1742
let toggled = !doc_buffer. is_empty ( ) ;
1738
1743
if toggled {
1739
1744
let method_toggle_class = if item_type. is_method ( ) { " method-toggle" } else { "" } ;
1740
- write_str (
1741
- w,
1742
- format_args ! ( "<details class=\" toggle{method_toggle_class}\" open><summary>" ) ,
1743
- ) ;
1745
+ write ! ( w, "<details class=\" toggle{method_toggle_class}\" open><summary>" ) ?;
1744
1746
}
1745
1747
match & item. kind {
1746
1748
clean:: MethodItem ( ..) | clean:: RequiredMethodItem ( _) => {
@@ -1755,172 +1757,151 @@ fn render_impl(
1755
1757
. find ( |item| item. name . map ( |n| n == * name) . unwrap_or ( false ) )
1756
1758
} )
1757
1759
. map ( |item| format ! ( "{}.{name}" , item. type_( ) ) ) ;
1758
- write_str (
1760
+ write ! (
1759
1761
w,
1760
- format_args ! (
1761
- "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1762
+ "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1762
1763
{}",
1763
- render_rightside( cx, item, render_mode)
1764
- ) ,
1765
- ) ;
1764
+ render_rightside( cx, item, render_mode)
1765
+ ) ?;
1766
1766
if trait_. is_some ( ) {
1767
1767
// Anchors are only used on trait impls.
1768
- write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1768
+ write ! ( w, "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ? ;
1769
1769
}
1770
- write_str (
1770
+ write ! (
1771
1771
w,
1772
- format_args ! (
1773
- "<h4 class=\" code-header\" >{}</h4></section>" ,
1774
- render_assoc_item(
1775
- item,
1776
- link. anchor( source_id. as_ref( ) . unwrap_or( & id) ) ,
1777
- ItemType :: Impl ,
1778
- cx,
1779
- render_mode,
1780
- ) ,
1772
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1773
+ render_assoc_item(
1774
+ item,
1775
+ link. anchor( source_id. as_ref( ) . unwrap_or( & id) ) ,
1776
+ ItemType :: Impl ,
1777
+ cx,
1778
+ render_mode,
1781
1779
) ,
1782
- ) ;
1780
+ ) ? ;
1783
1781
}
1784
1782
}
1785
1783
clean:: RequiredAssocConstItem ( generics, ty) => {
1786
1784
let source_id = format ! ( "{item_type}.{name}" ) ;
1787
1785
let id = cx. derive_id ( & source_id) ;
1788
- write_str (
1786
+ write ! (
1789
1787
w,
1790
- format_args ! (
1791
- "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1788
+ "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1792
1789
{}",
1793
- render_rightside( cx, item, render_mode)
1794
- ) ,
1795
- ) ;
1790
+ render_rightside( cx, item, render_mode)
1791
+ ) ?;
1796
1792
if trait_. is_some ( ) {
1797
1793
// Anchors are only used on trait impls.
1798
- write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1794
+ write ! ( w, "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ? ;
1799
1795
}
1800
- write_str (
1796
+ write ! (
1801
1797
w,
1802
- format_args ! (
1803
- "<h4 class=\" code-header\" >{}</h4></section>" ,
1804
- assoc_const(
1805
- item,
1806
- generics,
1807
- ty,
1808
- AssocConstValue :: None ,
1809
- link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1810
- 0 ,
1811
- cx,
1812
- )
1798
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1799
+ assoc_const(
1800
+ item,
1801
+ generics,
1802
+ ty,
1803
+ AssocConstValue :: None ,
1804
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1805
+ 0 ,
1806
+ cx,
1813
1807
) ,
1814
- ) ;
1808
+ ) ? ;
1815
1809
}
1816
1810
clean:: ProvidedAssocConstItem ( ci) | clean:: ImplAssocConstItem ( ci) => {
1817
1811
let source_id = format ! ( "{item_type}.{name}" ) ;
1818
1812
let id = cx. derive_id ( & source_id) ;
1819
- write_str (
1813
+ write ! (
1820
1814
w,
1821
- format_args ! (
1822
- "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1815
+ "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1823
1816
{}",
1824
- render_rightside( cx, item, render_mode)
1825
- ) ,
1826
- ) ;
1817
+ render_rightside( cx, item, render_mode) ,
1818
+ ) ?;
1827
1819
if trait_. is_some ( ) {
1828
1820
// Anchors are only used on trait impls.
1829
- write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1821
+ write ! ( w, "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ? ;
1830
1822
}
1831
- write_str (
1823
+ write ! (
1832
1824
w,
1833
- format_args ! (
1834
- "<h4 class=\" code-header\" >{}</h4></section>" ,
1835
- assoc_const(
1836
- item,
1837
- & ci. generics,
1838
- & ci. type_,
1839
- match item. kind {
1840
- clean:: ProvidedAssocConstItem ( _) =>
1841
- AssocConstValue :: TraitDefault ( & ci. kind) ,
1842
- clean:: ImplAssocConstItem ( _) => AssocConstValue :: Impl ( & ci. kind) ,
1843
- _ => unreachable!( ) ,
1844
- } ,
1845
- link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1846
- 0 ,
1847
- cx,
1848
- )
1825
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1826
+ assoc_const(
1827
+ item,
1828
+ & ci. generics,
1829
+ & ci. type_,
1830
+ match item. kind {
1831
+ clean:: ProvidedAssocConstItem ( _) =>
1832
+ AssocConstValue :: TraitDefault ( & ci. kind) ,
1833
+ clean:: ImplAssocConstItem ( _) => AssocConstValue :: Impl ( & ci. kind) ,
1834
+ _ => unreachable!( ) ,
1835
+ } ,
1836
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1837
+ 0 ,
1838
+ cx,
1849
1839
) ,
1850
- ) ;
1840
+ ) ? ;
1851
1841
}
1852
1842
clean:: RequiredAssocTypeItem ( generics, bounds) => {
1853
1843
let source_id = format ! ( "{item_type}.{name}" ) ;
1854
1844
let id = cx. derive_id ( & source_id) ;
1855
- write_str (
1845
+ write ! (
1856
1846
w,
1857
- format_args ! (
1858
- "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1847
+ "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1859
1848
{}",
1860
- render_rightside( cx, item, render_mode)
1861
- ) ,
1862
- ) ;
1849
+ render_rightside( cx, item, render_mode) ,
1850
+ ) ?;
1863
1851
if trait_. is_some ( ) {
1864
1852
// Anchors are only used on trait impls.
1865
- write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1853
+ write ! ( w, "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ? ;
1866
1854
}
1867
- write_str (
1855
+ write ! (
1868
1856
w,
1869
- format_args ! (
1870
- "<h4 class=\" code-header\" >{}</h4></section>" ,
1871
- assoc_type(
1872
- item,
1873
- generics,
1874
- bounds,
1875
- None ,
1876
- link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1877
- 0 ,
1878
- cx,
1879
- )
1857
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1858
+ assoc_type(
1859
+ item,
1860
+ generics,
1861
+ bounds,
1862
+ None ,
1863
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1864
+ 0 ,
1865
+ cx,
1880
1866
) ,
1881
- ) ;
1867
+ ) ? ;
1882
1868
}
1883
1869
clean:: AssocTypeItem ( tydef, _bounds) => {
1884
1870
let source_id = format ! ( "{item_type}.{name}" ) ;
1885
1871
let id = cx. derive_id ( & source_id) ;
1886
- write_str (
1872
+ write ! (
1887
1873
w,
1888
- format_args ! (
1889
- "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1874
+ "<section id=\" {id}\" class=\" {item_type}{in_trait_class}\" >\
1890
1875
{}",
1891
- render_rightside( cx, item, render_mode)
1892
- ) ,
1893
- ) ;
1876
+ render_rightside( cx, item, render_mode) ,
1877
+ ) ?;
1894
1878
if trait_. is_some ( ) {
1895
1879
// Anchors are only used on trait impls.
1896
- write_str ( w, format_args ! ( "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ) ;
1880
+ write ! ( w, "<a href=\" #{id}\" class=\" anchor\" >§</a>" ) ? ;
1897
1881
}
1898
- write_str (
1882
+ write ! (
1899
1883
w,
1900
- format_args ! (
1901
- "<h4 class=\" code-header\" >{}</h4></section>" ,
1902
- assoc_type(
1903
- item,
1904
- & tydef. generics,
1905
- & [ ] , // intentionally leaving out bounds
1906
- Some ( tydef. item_type. as_ref( ) . unwrap_or( & tydef. type_) ) ,
1907
- link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1908
- 0 ,
1909
- cx,
1910
- )
1884
+ "<h4 class=\" code-header\" >{}</h4></section>" ,
1885
+ assoc_type(
1886
+ item,
1887
+ & tydef. generics,
1888
+ & [ ] , // intentionally leaving out bounds
1889
+ Some ( tydef. item_type. as_ref( ) . unwrap_or( & tydef. type_) ) ,
1890
+ link. anchor( if trait_. is_some( ) { & source_id } else { & id } ) ,
1891
+ 0 ,
1892
+ cx,
1911
1893
) ,
1912
- ) ;
1894
+ ) ? ;
1913
1895
}
1914
- clean:: StrippedItem ( ..) => return ,
1896
+ clean:: StrippedItem ( ..) => return Ok ( ( ) ) ,
1915
1897
_ => panic ! ( "can't make docs for trait item with name {:?}" , item. name) ,
1916
1898
}
1917
1899
1918
- w. push_str ( & info_buffer) ;
1900
+ w. write_str ( & info_buffer) ? ;
1919
1901
if toggled {
1920
- w. push_str ( "</summary>" ) ;
1921
- w. push_str ( & doc_buffer) ;
1922
- w. push_str ( "</details>" ) ;
1902
+ write ! ( w, "</summary>{doc_buffer}</details>" ) ?;
1923
1903
}
1904
+ Ok ( ( ) )
1924
1905
}
1925
1906
1926
1907
let mut impl_items = String :: new ( ) ;
@@ -1963,7 +1944,7 @@ fn render_impl(
1963
1944
false ,
1964
1945
trait_,
1965
1946
rendering_params,
1966
- ) ;
1947
+ ) ? ;
1967
1948
}
1968
1949
_ => { }
1969
1950
}
@@ -1981,7 +1962,7 @@ fn render_impl(
1981
1962
false ,
1982
1963
trait_,
1983
1964
rendering_params,
1984
- ) ;
1965
+ ) ? ;
1985
1966
}
1986
1967
for method in methods {
1987
1968
doc_impl_item (
@@ -1995,20 +1976,20 @@ fn render_impl(
1995
1976
false ,
1996
1977
trait_,
1997
1978
rendering_params,
1998
- ) ;
1979
+ ) ? ;
1999
1980
}
2000
1981
}
2001
1982
2002
1983
fn render_default_items (
2003
- boring : & mut String ,
2004
- interesting : & mut String ,
1984
+ mut boring : impl fmt :: Write ,
1985
+ mut interesting : impl fmt :: Write ,
2005
1986
cx : & Context < ' _ > ,
2006
1987
t : & clean:: Trait ,
2007
1988
i : & clean:: Impl ,
2008
1989
parent : & clean:: Item ,
2009
1990
render_mode : RenderMode ,
2010
1991
rendering_params : ImplRenderingParameters ,
2011
- ) {
1992
+ ) -> fmt :: Result {
2012
1993
for trait_item in & t. items {
2013
1994
// Skip over any default trait items that are impossible to reference
2014
1995
// (e.g. if it has a `Self: Sized` bound on an unsized type).
@@ -2028,8 +2009,8 @@ fn render_impl(
2028
2009
let assoc_link = AssocItemLink :: GotoSource ( did. into ( ) , & provided_methods) ;
2029
2010
2030
2011
doc_impl_item (
2031
- boring,
2032
- interesting,
2012
+ & mut boring,
2013
+ & mut interesting,
2033
2014
cx,
2034
2015
trait_item,
2035
2016
parent,
@@ -2038,8 +2019,9 @@ fn render_impl(
2038
2019
true ,
2039
2020
Some ( t) ,
2040
2021
rendering_params,
2041
- ) ;
2022
+ ) ? ;
2042
2023
}
2024
+ Ok ( ( ) )
2043
2025
}
2044
2026
2045
2027
// If we've implemented a trait, then also emit documentation for all
@@ -2059,7 +2041,7 @@ fn render_impl(
2059
2041
& i. impl_item ,
2060
2042
render_mode,
2061
2043
rendering_params,
2062
- ) ;
2044
+ ) ? ;
2063
2045
}
2064
2046
}
2065
2047
if render_mode == RenderMode :: Normal {
0 commit comments