@@ -249,8 +249,10 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
249
249
clean:: TypeAliasItem ( ref t) => {
250
250
write_str ( buf, format_args ! ( "{}" , item_type_alias( cx, item, t) ) )
251
251
}
252
- clean:: MacroItem ( ref m) => item_macro ( buf, cx, item, m) ,
253
- clean:: ProcMacroItem ( ref m) => item_proc_macro ( buf, cx, item, m) ,
252
+ clean:: MacroItem ( ref m) => write_str ( buf, format_args ! ( "{}" , item_macro( cx, item, m) ) ) ,
253
+ clean:: ProcMacroItem ( ref m) => {
254
+ write_str ( buf, format_args ! ( "{}" , item_proc_macro( cx, item, m) ) )
255
+ }
254
256
clean:: PrimitiveItem ( _) => item_primitive ( buf, cx, item) ,
255
257
clean:: StaticItem ( ref i) => item_static ( buf, cx, item, i, None ) ,
256
258
clean:: ForeignStaticItem ( ref i, safety) => item_static ( buf, cx, item, i, Some ( * safety) ) ,
@@ -1873,51 +1875,56 @@ fn item_variants<'a, 'tcx>(
1873
1875
} )
1874
1876
}
1875
1877
1876
- fn item_macro ( w : & mut String , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Macro ) {
1877
- wrap_item ( w, |w| {
1878
- // FIXME: Also print `#[doc(hidden)]` for `macro_rules!` if it `is_doc_hidden`.
1879
- if !t. macro_rules {
1880
- write_str ( w, format_args ! ( "{}" , visibility_print_with_space( it, cx) ) ) ;
1881
- }
1882
- write_str ( w, format_args ! ( "{}" , Escape ( & t. source) ) ) ;
1883
- } ) ;
1884
- write_str ( w, format_args ! ( "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ) ;
1878
+ fn item_macro < ' a , ' tcx > (
1879
+ cx : & ' a Context < ' tcx > ,
1880
+ it : & ' a clean:: Item ,
1881
+ t : & ' a clean:: Macro ,
1882
+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1883
+ fmt:: from_fn ( |w| {
1884
+ wrap_item ( w, |w| {
1885
+ // FIXME: Also print `#[doc(hidden)]` for `macro_rules!` if it `is_doc_hidden`.
1886
+ if !t. macro_rules {
1887
+ write ! ( w, "{}" , visibility_print_with_space( it, cx) ) ?;
1888
+ }
1889
+ write ! ( w, "{}" , Escape ( & t. source) )
1890
+ } ) ?;
1891
+ write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) )
1892
+ } )
1885
1893
}
1886
1894
1887
- fn item_proc_macro (
1888
- w : & mut impl fmt:: Write ,
1889
- cx : & Context < ' _ > ,
1890
- it : & clean:: Item ,
1891
- m : & clean:: ProcMacro ,
1892
- ) {
1893
- wrap_item ( w, |buffer| {
1894
- let name = it. name . expect ( "proc-macros always have names" ) ;
1895
- match m. kind {
1896
- MacroKind :: Bang => {
1897
- write ! ( buffer, "{name}!() {{ <span class=\" comment\" >/* proc-macro */</span> }}" )
1898
- . unwrap ( ) ;
1899
- }
1900
- MacroKind :: Attr => {
1901
- write ! ( buffer, "#[{name}]" ) . unwrap ( ) ;
1902
- }
1903
- MacroKind :: Derive => {
1904
- write ! ( buffer, "#[derive({name})]" ) . unwrap ( ) ;
1905
- if !m. helpers . is_empty ( ) {
1906
- buffer
1907
- . write_str (
1895
+ fn item_proc_macro < ' a , ' tcx > (
1896
+ cx : & ' a Context < ' tcx > ,
1897
+ it : & ' a clean:: Item ,
1898
+ m : & ' a clean:: ProcMacro ,
1899
+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
1900
+ fmt:: from_fn ( |w| {
1901
+ wrap_item ( w, |w| {
1902
+ let name = it. name . expect ( "proc-macros always have names" ) ;
1903
+ match m. kind {
1904
+ MacroKind :: Bang => {
1905
+ write ! ( w, "{name}!() {{ <span class=\" comment\" >/* proc-macro */</span> }}" ) ?;
1906
+ }
1907
+ MacroKind :: Attr => {
1908
+ write ! ( w, "#[{name}]" ) ?;
1909
+ }
1910
+ MacroKind :: Derive => {
1911
+ write ! ( w, "#[derive({name})]" ) ?;
1912
+ if !m. helpers . is_empty ( ) {
1913
+ w. write_str (
1908
1914
"\n {\n \
1909
- <span class=\" comment\" >// Attributes available to this derive:</span>\n ",
1910
- )
1911
- . unwrap ( ) ;
1912
- for attr in & m. helpers {
1913
- writeln ! ( buffer, " #[{attr}]" ) . unwrap ( ) ;
1915
+ <span class=\" comment\" >// Attributes available to this derive:</span>\n ",
1916
+ ) ?;
1917
+ for attr in & m. helpers {
1918
+ writeln ! ( w, " #[{attr}]" ) ?;
1919
+ }
1920
+ w. write_str ( "}\n " ) ?;
1914
1921
}
1915
- buffer. write_str ( "}\n " ) . unwrap ( ) ;
1916
1922
}
1917
1923
}
1918
- }
1919
- } ) ;
1920
- write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) . unwrap ( ) ;
1924
+ Ok ( ( ) )
1925
+ } ) ?;
1926
+ write ! ( w, "{}" , document( cx, it, None , HeadingOffset :: H2 ) )
1927
+ } )
1921
1928
}
1922
1929
1923
1930
fn item_primitive ( w : & mut impl fmt:: Write , cx : & Context < ' _ > , it : & clean:: Item ) {
0 commit comments