@@ -951,16 +951,15 @@ fn assoc_type(
951
951
write_str ( w, format_args ! ( "{}" , print_where_clause( generics, cx, indent, Ending :: NoNewline ) ) ) ;
952
952
}
953
953
954
- fn assoc_method (
955
- w : & mut String ,
956
- meth : & clean:: Item ,
957
- g : & clean:: Generics ,
958
- d : & clean:: FnDecl ,
959
- link : AssocItemLink < ' _ > ,
954
+ fn assoc_method < ' a , ' tcx > (
955
+ meth : & ' a clean:: Item ,
956
+ g : & ' a clean:: Generics ,
957
+ d : & ' a clean:: FnDecl ,
958
+ link : AssocItemLink < ' a > ,
960
959
parent : ItemType ,
961
- cx : & Context < ' _ > ,
960
+ cx : & ' a Context < ' tcx > ,
962
961
render_mode : RenderMode ,
963
- ) {
962
+ ) -> impl fmt :: Display + ' a + Captures < ' tcx > {
964
963
let tcx = cx. tcx ( ) ;
965
964
let header = meth. fn_header ( tcx) . expect ( "Trying to get header from a non-function item" ) ;
966
965
let name = meth. name . as_ref ( ) . unwrap ( ) ;
@@ -976,54 +975,46 @@ fn assoc_method(
976
975
) ,
977
976
RenderMode :: ForDeref { .. } => "" ,
978
977
} ;
979
- let asyncness = header . asyncness . print_with_space ( ) ;
980
- let safety = header . safety . print_with_space ( ) ;
981
- let abi = print_abi_with_space ( header. abi ) . to_string ( ) ;
982
- let href = assoc_href_attr ( meth , link , cx ) . maybe_display ( ) ;
983
-
984
- // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
985
- let generics_len = format ! ( "{:#}" , g . print ( cx ) ) . len ( ) ;
986
- let mut header_len = "fn " . len ( )
987
- + vis . len ( )
988
- + defaultness . len ( )
989
- + constness . len ( )
990
- + asyncness . len ( )
991
- + safety . len ( )
992
- + abi . len ( )
993
- + name . as_str ( ) . len ( )
994
- + generics_len ;
995
-
996
- let notable_traits = notable_traits_button ( & d . output , cx ) . maybe_display ( ) ;
997
-
998
- let ( indent , indent_str , end_newline ) = if parent == ItemType :: Trait {
999
- header_len += 4 ;
1000
- let indent_str = " " ;
1001
- write_str ( w , format_args ! ( "{}" , render_attributes_in_pre ( meth , indent_str , cx ) ) ) ;
1002
- ( 4 , indent_str, Ending :: NoNewline )
1003
- } else {
1004
- render_attributes_in_code ( w , meth , cx ) ;
1005
- ( 0 , "" , Ending :: Newline )
1006
- } ;
1007
- w . reserve ( header_len + "<a href= \" \" class= \" fn \" >{" . len ( ) + "</a>" . len ( ) ) ;
1008
- write_str (
1009
- w ,
1010
- format_args ! (
978
+
979
+ fmt :: from_fn ( move |w| {
980
+ let asyncness = header. asyncness . print_with_space ( ) ;
981
+ let safety = header . safety . print_with_space ( ) ;
982
+ let abi = print_abi_with_space ( header . abi ) . to_string ( ) ;
983
+ let href = assoc_href_attr ( meth , link , cx ) . maybe_display ( ) ;
984
+
985
+ // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`.
986
+ let generics_len = format ! ( "{:#}" , g . print ( cx ) ) . len ( ) ;
987
+ let mut header_len = "fn " . len ( )
988
+ + vis . len ( )
989
+ + defaultness . len ( )
990
+ + constness . len ( )
991
+ + asyncness . len ( )
992
+ + safety . len ( )
993
+ + abi . len ( )
994
+ + name . as_str ( ) . len ( )
995
+ + generics_len ;
996
+
997
+ let notable_traits = notable_traits_button ( & d . output , cx ) . maybe_display ( ) ;
998
+
999
+ let ( indent , indent_str, end_newline ) = if parent == ItemType :: Trait {
1000
+ header_len += 4 ;
1001
+ let indent_str = " " ;
1002
+ write ! ( w , "{}" , render_attributes_in_pre ( meth , indent_str , cx ) ) ? ;
1003
+ ( 4 , indent_str , Ending :: NoNewline )
1004
+ } else {
1005
+ render_attributes_in_code ( w , meth , cx ) ;
1006
+ ( 0 , "" , Ending :: Newline )
1007
+ } ;
1008
+ write ! (
1009
+ w ,
1011
1010
"{indent}{vis}{defaultness}{constness}{asyncness}{safety}{abi}fn \
1012
- <a{href} class=\" fn\" >{name}</a>{generics}{decl}{notable_traits}{where_clause}",
1011
+ <a{href} class=\" fn\" >{name}</a>{generics}{decl}{notable_traits}{where_clause}",
1013
1012
indent = indent_str,
1014
- vis = vis,
1015
- defaultness = defaultness,
1016
- constness = constness,
1017
- asyncness = asyncness,
1018
- safety = safety,
1019
- abi = abi,
1020
- href = href,
1021
- name = name,
1022
1013
generics = g. print( cx) ,
1023
1014
decl = d. full_print( header_len, indent, cx) ,
1024
1015
where_clause = print_where_clause( g, cx, indent, end_newline) ,
1025
- ) ,
1026
- ) ;
1016
+ )
1017
+ } )
1027
1018
}
1028
1019
1029
1020
/// Writes a span containing the versions at which an item became stable and/or const-stable. For
@@ -1132,11 +1123,14 @@ fn render_assoc_item(
1132
1123
) {
1133
1124
match & item. kind {
1134
1125
clean:: StrippedItem ( ..) => { }
1135
- clean:: RequiredMethodItem ( m) => {
1136
- assoc_method ( w, item, & m. generics , & m. decl , link, parent, cx, render_mode)
1137
- }
1138
- clean:: MethodItem ( m, _) => {
1139
- assoc_method ( w, item, & m. generics , & m. decl , link, parent, cx, render_mode)
1126
+ clean:: RequiredMethodItem ( m) | clean:: MethodItem ( m, _) => {
1127
+ write_str (
1128
+ w,
1129
+ format_args ! (
1130
+ "{}" ,
1131
+ assoc_method( item, & m. generics, & m. decl, link, parent, cx, render_mode)
1132
+ ) ,
1133
+ ) ;
1140
1134
}
1141
1135
clean:: RequiredAssocConstItem ( generics, ty) => assoc_const (
1142
1136
w,
0 commit comments