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