@@ -251,7 +251,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut String)
251
251
write_str ( buf, format_args ! ( "{}" , item_module( cx, item, & m. items) ) )
252
252
}
253
253
clean:: FunctionItem ( ref f) | clean:: ForeignFunctionItem ( ref f, _) => {
254
- item_function ( buf, cx, item, f)
254
+ write_str ( buf, format_args ! ( "{}" , item_function ( cx, item, f) ) )
255
255
}
256
256
clean:: TraitItem ( ref t) => item_trait ( buf, cx, item, t) ,
257
257
clean:: StructItem ( ref s) => item_struct ( buf, cx, item, s) ,
@@ -587,44 +587,47 @@ fn extra_info_tags<'a, 'tcx: 'a>(
587
587
} )
588
588
}
589
589
590
- fn item_function ( w : & mut String , cx : & Context < ' _ > , it : & clean:: Item , f : & clean:: Function ) {
591
- let tcx = cx. tcx ( ) ;
592
- let header = it. fn_header ( tcx) . expect ( "printing a function which isn't a function" ) ;
593
- debug ! (
594
- "item_function/const: {:?} {:?} {:?} {:?}" ,
595
- it. name,
596
- & header. constness,
597
- it. stable_since( tcx) ,
598
- it. const_stability( tcx) ,
599
- ) ;
600
- let constness = print_constness_with_space (
601
- & header. constness ,
602
- it. stable_since ( tcx) ,
603
- it. const_stability ( tcx) ,
604
- ) ;
605
- let safety = header. safety . print_with_space ( ) ;
606
- let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
607
- let asyncness = header. asyncness . print_with_space ( ) ;
608
- let visibility = visibility_print_with_space ( it, cx) . to_string ( ) ;
609
- let name = it. name . unwrap ( ) ;
610
-
611
- let generics_len = format ! ( "{:#}" , f. generics. print( cx) ) . len ( ) ;
612
- let header_len = "fn " . len ( )
613
- + visibility. len ( )
614
- + constness. len ( )
615
- + asyncness. len ( )
616
- + safety. len ( )
617
- + abi. len ( )
618
- + name. as_str ( ) . len ( )
619
- + generics_len;
620
-
621
- let notable_traits = notable_traits_button ( & f. decl . output , cx) . maybe_display ( ) ;
622
-
623
- wrap_item ( w, |w| {
624
- w. reserve ( header_len) ;
625
- write_str (
626
- w,
627
- format_args ! (
590
+ fn item_function < ' a , ' tcx > (
591
+ cx : & ' a Context < ' tcx > ,
592
+ it : & ' a clean:: Item ,
593
+ f : & ' a clean:: Function ,
594
+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
595
+ fmt:: from_fn ( |w| {
596
+ let tcx = cx. tcx ( ) ;
597
+ let header = it. fn_header ( tcx) . expect ( "printing a function which isn't a function" ) ;
598
+ debug ! (
599
+ "item_function/const: {:?} {:?} {:?} {:?}" ,
600
+ it. name,
601
+ & header. constness,
602
+ it. stable_since( tcx) ,
603
+ it. const_stability( tcx) ,
604
+ ) ;
605
+ let constness = print_constness_with_space (
606
+ & header. constness ,
607
+ it. stable_since ( tcx) ,
608
+ it. const_stability ( tcx) ,
609
+ ) ;
610
+ let safety = header. safety . print_with_space ( ) ;
611
+ let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
612
+ let asyncness = header. asyncness . print_with_space ( ) ;
613
+ let visibility = visibility_print_with_space ( it, cx) . to_string ( ) ;
614
+ let name = it. name . unwrap ( ) ;
615
+
616
+ let generics_len = format ! ( "{:#}" , f. generics. print( cx) ) . len ( ) ;
617
+ let header_len = "fn " . len ( )
618
+ + visibility. len ( )
619
+ + constness. len ( )
620
+ + asyncness. len ( )
621
+ + safety. len ( )
622
+ + abi. len ( )
623
+ + name. as_str ( ) . len ( )
624
+ + generics_len;
625
+
626
+ let notable_traits = notable_traits_button ( & f. decl . output , cx) . maybe_display ( ) ;
627
+
628
+ wrap_item ( w, |w| {
629
+ write ! (
630
+ w,
628
631
"{attrs}{vis}{constness}{asyncness}{safety}{abi}fn \
629
632
{name}{generics}{decl}{notable_traits}{where_clause}",
630
633
attrs = render_attributes_in_pre( it, "" , cx) ,
@@ -637,10 +640,10 @@ fn item_function(w: &mut String, cx: &Context<'_>, it: &clean::Item, f: &clean::
637
640
generics = f. generics. print( cx) ,
638
641
where_clause = print_where_clause( & f. generics, cx, 0 , Ending :: Newline ) ,
639
642
decl = f. decl. full_print( header_len, 0 , cx) ,
640
- ) ,
641
- ) ;
642
- } ) ;
643
- write_str ( w , format_args ! ( "{}" , document ( cx , it , None , HeadingOffset :: H2 ) ) ) ;
643
+ )
644
+ } ) ? ;
645
+ write ! ( w , "{}" , document ( cx , it , None , HeadingOffset :: H2 ) )
646
+ } )
644
647
}
645
648
646
649
fn item_trait ( w : & mut String , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Trait ) {
@@ -2249,14 +2252,15 @@ fn bounds<'a, 'tcx>(
2249
2252
. maybe_display ( )
2250
2253
}
2251
2254
2252
- fn wrap_item < W , F > ( w : & mut W , f : F )
2255
+ fn wrap_item < W , F , T > ( w : & mut W , f : F ) -> T
2253
2256
where
2254
2257
W : fmt:: Write ,
2255
- F : FnOnce ( & mut W ) ,
2258
+ F : FnOnce ( & mut W ) -> T ,
2256
2259
{
2257
2260
write ! ( w, r#"<pre class="rust item-decl"><code>"# ) . unwrap ( ) ;
2258
- f ( w) ;
2261
+ let res = f ( w) ;
2259
2262
write ! ( w, "</code></pre>" ) . unwrap ( ) ;
2263
+ res
2260
2264
}
2261
2265
2262
2266
#[ derive( PartialEq , Eq ) ]
0 commit comments