@@ -1334,7 +1334,7 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
13341334 ) ,
13351335 ) ;
13361336 } ) ;
1337- item_fields ( w, cx, it, fields, None ) ;
1337+ write_str ( w, format_args ! ( "{}" , item_fields ( cx, it, fields, None ) ) ) ;
13381338 }
13391339 clean:: TypeAliasInnerType :: Struct { ctor_kind, fields } => {
13401340 wrap_item ( w, |w| {
@@ -1359,7 +1359,7 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
13591359 ) ,
13601360 ) ;
13611361 } ) ;
1362- item_fields ( w, cx, it, fields, None ) ;
1362+ write_str ( w, format_args ! ( "{}" , item_fields ( cx, it, fields, None ) ) ) ;
13631363 }
13641364 }
13651365 }
@@ -1993,67 +1993,73 @@ fn item_struct(w: &mut String, cx: &Context<'_>, it: &clean::Item, s: &clean::St
19931993 ) ;
19941994 } ) ;
19951995
1996- write_str ( w, format_args ! ( "{}" , document( cx, it, None , HeadingOffset :: H2 ) ) ) ;
1997-
1998- item_fields ( w, cx, it, & s. fields , s. ctor_kind ) ;
1999-
20001996 let def_id = it. item_id . expect_def_id ( ) ;
2001- write_str ( w, format_args ! ( "{}" , render_assoc_items( cx, it, def_id, AssocItemRender :: All ) ) ) ;
2002- write_str ( w, format_args ! ( "{}" , document_type_layout( cx, def_id) ) ) ;
1997+
1998+ write_str (
1999+ w,
2000+ format_args ! (
2001+ "{}{}{}{}" ,
2002+ document( cx, it, None , HeadingOffset :: H2 ) ,
2003+ item_fields( cx, it, & s. fields, s. ctor_kind) ,
2004+ render_assoc_items( cx, it, def_id, AssocItemRender :: All ) ,
2005+ document_type_layout( cx, def_id) ,
2006+ ) ,
2007+ ) ;
20032008}
20042009
2005- fn item_fields (
2006- w : & mut String ,
2007- cx : & Context < ' _ > ,
2008- it : & clean:: Item ,
2009- fields : & [ clean:: Item ] ,
2010+ fn item_fields < ' a , ' tcx > (
2011+ cx : & ' a Context < ' tcx > ,
2012+ it : & ' a clean:: Item ,
2013+ fields : & ' a [ clean:: Item ] ,
20102014 ctor_kind : Option < CtorKind > ,
2011- ) {
2012- let mut fields = fields
2013- . iter ( )
2014- . filter_map ( |f| match f . kind {
2015- clean :: StructFieldItem ( ref ty ) => Some ( ( f , ty ) ) ,
2016- _ => None ,
2017- } )
2018- . peekable ( ) ;
2019- if let None | Some ( CtorKind :: Fn ) = ctor_kind {
2020- if fields . peek ( ) . is_some ( ) {
2021- let title = format ! (
2022- "{}{}" ,
2023- if ctor_kind . is_none ( ) { "Fields" } else { "Tuple Fields" } ,
2024- document_non_exhaustive_header ( it ) ,
2025- ) ;
2026- write_str (
2027- w ,
2028- format_args ! (
2015+ ) -> impl fmt :: Display + ' a + Captures < ' tcx > {
2016+ fmt :: from_fn ( move |w| {
2017+ let mut fields = fields
2018+ . iter ( )
2019+ . filter_map ( |f| match f . kind {
2020+ clean :: StructFieldItem ( ref ty ) => Some ( ( f , ty ) ) ,
2021+ _ => None ,
2022+ } )
2023+ . peekable ( ) ;
2024+ if let None | Some ( CtorKind :: Fn ) = ctor_kind {
2025+ if fields . peek ( ) . is_some ( ) {
2026+ let title = format ! (
2027+ "{}{}" ,
2028+ if ctor_kind . is_none ( ) { "Fields" } else { "Tuple Fields" } ,
2029+ document_non_exhaustive_header ( it ) ,
2030+ ) ;
2031+ write ! (
2032+ w ,
20292033 "{}" ,
20302034 write_section_heading(
20312035 & title,
20322036 "fields" ,
20332037 Some ( "fields" ) ,
20342038 document_non_exhaustive( it)
20352039 )
2036- ) ,
2037- ) ;
2038- for ( index , ( field , ty ) ) in fields . enumerate ( ) {
2039- let field_name =
2040- field . name . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
2041- let id = cx . derive_id ( format ! ( "{typ}.{field_name}" , typ = ItemType :: StructField ) ) ;
2042- write_str (
2043- w ,
2044- format_args ! (
2040+ ) ? ;
2041+ for ( index , ( field , ty ) ) in fields . enumerate ( ) {
2042+ let field_name = field
2043+ . name
2044+ . map_or_else ( || index. to_string ( ) , |sym| sym. as_str ( ) . to_string ( ) ) ;
2045+ let id =
2046+ cx . derive_id ( format ! ( "{typ}.{field_name}" , typ = ItemType :: StructField ) ) ;
2047+ write ! (
2048+ w ,
20452049 "<span id=\" {id}\" class=\" {item_type} section-header\" >\
20462050 <a href=\" #{id}\" class=\" anchor field\" >§</a>\
20472051 <code>{field_name}: {ty}</code>\
2048- </span>",
2052+ </span>\
2053+ {doc}",
20492054 item_type = ItemType :: StructField ,
2050- ty = ty. print( cx)
2051- ) ,
2052- ) ;
2053- write_str ( w , format_args ! ( "{}" , document ( cx , field , Some ( it ) , HeadingOffset :: H3 ) ) ) ;
2055+ ty = ty. print( cx) ,
2056+ doc = document ( cx , field , Some ( it ) , HeadingOffset :: H3 ) ,
2057+ ) ? ;
2058+ }
20542059 }
20552060 }
2056- }
2061+ Ok ( ( ) )
2062+ } )
20572063}
20582064
20592065fn item_static (
0 commit comments