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