@@ -22,7 +22,9 @@ use crate::clean::{self, GetDefId};
2222use crate :: formats:: item_type:: ItemType ;
2323use crate :: formats:: { AssocItemRender , Impl , RenderMode } ;
2424use crate :: html:: escape:: Escape ;
25- use crate :: html:: format:: { print_abi_with_space, print_where_clause, Buffer , PrintWithSpace } ;
25+ use crate :: html:: format:: {
26+ print_abi_with_space, print_constness_with_space, print_where_clause, Buffer , PrintWithSpace ,
27+ } ;
2628use crate :: html:: highlight;
2729use crate :: html:: layout:: Page ;
2830use crate :: html:: markdown:: MarkdownSummaryLine ;
@@ -430,29 +432,36 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
430432}
431433
432434fn item_function ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , f : & clean:: Function ) {
433- let header_len = format ! (
434- "{}{}{}{}{:#}fn {}{:#}" ,
435- it. visibility. print_with_space( it. def_id, cx) ,
436- f. header. constness. print_with_space( ) ,
437- f. header. asyncness. print_with_space( ) ,
438- f. header. unsafety. print_with_space( ) ,
439- print_abi_with_space( f. header. abi) ,
440- it. name. as_ref( ) . unwrap( ) ,
441- f. generics. print( cx) ,
442- )
443- . len ( ) ;
435+ let vis = it. visibility . print_with_space ( it. def_id , cx) . to_string ( ) ;
436+ let constness = print_constness_with_space ( & f. header . constness , it. const_stability ( cx. tcx ( ) ) ) ;
437+ let asyncness = f. header . asyncness . print_with_space ( ) ;
438+ let unsafety = f. header . unsafety . print_with_space ( ) ;
439+ let abi = print_abi_with_space ( f. header . abi ) . to_string ( ) ;
440+ let name = it. name . as_ref ( ) . unwrap ( ) ;
441+
442+ let generics_len = format ! ( "{:#}" , f. generics. print( cx) ) . len ( ) ;
443+ let header_len = "fn " . len ( )
444+ + vis. len ( )
445+ + constness. len ( )
446+ + asyncness. len ( )
447+ + unsafety. len ( )
448+ + abi. len ( )
449+ + name. as_str ( ) . len ( )
450+ + generics_len;
451+
444452 w. write_str ( "<pre class=\" rust fn\" >" ) ;
445453 render_attributes_in_pre ( w, it, "" ) ;
454+ w. reserve ( header_len) ;
446455 write ! (
447456 w,
448457 "{vis}{constness}{asyncness}{unsafety}{abi}fn \
449458 {name}{generics}{decl}{notable_traits}{where_clause}</pre>",
450- vis = it . visibility . print_with_space ( it . def_id , cx ) ,
451- constness = f . header . constness. print_with_space ( ) ,
452- asyncness = f . header . asyncness. print_with_space ( ) ,
453- unsafety = f . header . unsafety. print_with_space ( ) ,
454- abi = print_abi_with_space ( f . header . abi) ,
455- name = it . name. as_ref ( ) . unwrap ( ) ,
459+ vis = vis ,
460+ constness = constness,
461+ asyncness = asyncness,
462+ unsafety = unsafety,
463+ abi = abi,
464+ name = name,
456465 generics = f. generics. print( cx) ,
457466 where_clause = print_where_clause( & f. generics, cx, 0 , true ) ,
458467 decl = f. decl. full_print( header_len, 0 , f. header. asyncness, cx) ,
0 commit comments