@@ -1318,17 +1318,20 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
13181318
13191319 write_str (
13201320 w,
1321- format_args ! ( "union {}{}" , it. name. unwrap( ) , t. generics. print( cx) ) ,
1322- ) ;
1323- render_struct_fields (
1324- w,
1325- Some ( & t. generics ) ,
1326- None ,
1327- fields,
1328- "" ,
1329- true ,
1330- has_stripped_fields,
1331- cx,
1321+ format_args ! (
1322+ "union {}{}{}" ,
1323+ it. name. unwrap( ) ,
1324+ t. generics. print( cx) ,
1325+ render_struct_fields(
1326+ Some ( & t. generics) ,
1327+ None ,
1328+ fields,
1329+ "" ,
1330+ true ,
1331+ has_stripped_fields,
1332+ cx,
1333+ )
1334+ ) ,
13321335 ) ;
13331336 } ) ;
13341337 item_fields ( w, cx, it, fields, None ) ;
@@ -1340,17 +1343,20 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
13401343
13411344 write_str (
13421345 w,
1343- format_args ! ( "struct {}{}" , it. name. unwrap( ) , t. generics. print( cx) ) ,
1344- ) ;
1345- render_struct_fields (
1346- w,
1347- Some ( & t. generics ) ,
1348- * ctor_kind,
1349- fields,
1350- "" ,
1351- true ,
1352- has_stripped_fields,
1353- cx,
1346+ format_args ! (
1347+ "struct {}{}{}" ,
1348+ it. name. unwrap( ) ,
1349+ t. generics. print( cx) ,
1350+ render_struct_fields(
1351+ Some ( & t. generics) ,
1352+ * ctor_kind,
1353+ fields,
1354+ "" ,
1355+ true ,
1356+ has_stripped_fields,
1357+ cx,
1358+ )
1359+ ) ,
13541360 ) ;
13551361 } ) ;
13561362 item_fields ( w, cx, it, fields, None ) ;
@@ -2365,144 +2371,141 @@ fn render_struct(
23652371 if let Some ( g) = g {
23662372 write_str ( w, format_args ! ( "{}" , g. print( cx) ) ) ;
23672373 }
2368- render_struct_fields (
2374+ write_str (
23692375 w,
2370- g,
2371- ty,
2372- fields,
2373- tab,
2374- structhead,
2375- it. has_stripped_entries ( ) . unwrap_or ( false ) ,
2376- cx,
2377- )
2376+ format_args ! (
2377+ "{}" ,
2378+ render_struct_fields(
2379+ g,
2380+ ty,
2381+ fields,
2382+ tab,
2383+ structhead,
2384+ it. has_stripped_entries( ) . unwrap_or( false ) ,
2385+ cx,
2386+ )
2387+ ) ,
2388+ ) ;
23782389}
23792390
2380- fn render_struct_fields (
2381- mut w : & mut String ,
2382- g : Option < & clean:: Generics > ,
2391+ fn render_struct_fields < ' a , ' tcx > (
2392+ g : Option < & ' a clean:: Generics > ,
23832393 ty : Option < CtorKind > ,
2384- fields : & [ clean:: Item ] ,
2385- tab : & str ,
2394+ fields : & ' a [ clean:: Item ] ,
2395+ tab : & ' a str ,
23862396 structhead : bool ,
23872397 has_stripped_entries : bool ,
2388- cx : & Context < ' _ > ,
2389- ) {
2390- match ty {
2391- None => {
2392- let where_displayed = if let Some ( generics) = g
2393- && let Some ( where_clause) = print_where_clause ( generics, cx, 0 , Ending :: Newline )
2394- {
2395- write_str ( w, format_args ! ( "{where_clause}" ) ) ;
2396- true
2397- } else {
2398- false
2399- } ;
2398+ cx : & ' a Context < ' tcx > ,
2399+ ) -> impl fmt:: Display + ' a + Captures < ' tcx > {
2400+ fmt:: from_fn ( move |w| {
2401+ match ty {
2402+ None => {
2403+ let where_displayed = if let Some ( generics) = g
2404+ && let Some ( where_clause) = print_where_clause ( generics, cx, 0 , Ending :: Newline )
2405+ {
2406+ write ! ( w, "{where_clause}" ) ?;
2407+ true
2408+ } else {
2409+ false
2410+ } ;
24002411
2401- // If there wasn't a `where` clause, we add a whitespace.
2402- if !where_displayed {
2403- w. push_str ( " {" ) ;
2404- } else {
2405- w. push_str ( "{" ) ;
2406- }
2407- let count_fields =
2408- fields. iter ( ) . filter ( |f| matches ! ( f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
2409- let has_visible_fields = count_fields > 0 ;
2410- let toggle = should_hide_fields ( count_fields) ;
2411- if toggle {
2412- toggle_open ( & mut w, format_args ! ( "{count_fields} fields" ) ) ;
2413- }
2414- for field in fields {
2415- if let clean:: StructFieldItem ( ref ty) = field. kind {
2416- write_str (
2417- w,
2418- format_args ! (
2412+ // If there wasn't a `where` clause, we add a whitespace.
2413+ if !where_displayed {
2414+ w. write_str ( " {" ) ?;
2415+ } else {
2416+ w. write_str ( "{" ) ?;
2417+ }
2418+ let count_fields =
2419+ fields. iter ( ) . filter ( |f| matches ! ( f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
2420+ let has_visible_fields = count_fields > 0 ;
2421+ let toggle = should_hide_fields ( count_fields) ;
2422+ if toggle {
2423+ toggle_open ( & mut * w, format_args ! ( "{count_fields} fields" ) ) ;
2424+ }
2425+ for field in fields {
2426+ if let clean:: StructFieldItem ( ref ty) = field. kind {
2427+ write ! (
2428+ w,
24192429 "\n {tab} {vis}{name}: {ty}," ,
24202430 vis = visibility_print_with_space( field, cx) ,
24212431 name = field. name. unwrap( ) ,
24222432 ty = ty. print( cx)
2423- ) ,
2424- ) ;
2433+ ) ? ;
2434+ }
24252435 }
2426- }
24272436
2428- if has_visible_fields {
2429- if has_stripped_entries {
2430- write_str (
2431- w,
2432- format_args ! (
2437+ if has_visible_fields {
2438+ if has_stripped_entries {
2439+ write ! (
2440+ w,
24332441 "\n {tab} <span class=\" comment\" >/* private fields */</span>"
2434- ) ,
2435- ) ;
2442+ ) ?;
2443+ }
2444+ write ! ( w, "\n {tab}" ) ?;
2445+ } else if has_stripped_entries {
2446+ write ! ( w, " <span class=\" comment\" >/* private fields */</span> " ) ?;
24362447 }
2437- write_str ( w, format_args ! ( "\n {tab}" ) ) ;
2438- } else if has_stripped_entries {
2439- write_str ( w, format_args ! ( " <span class=\" comment\" >/* private fields */</span> " ) ) ;
2440- }
2441- if toggle {
2442- toggle_close ( & mut w) ;
2448+ if toggle {
2449+ toggle_close ( & mut * w) ;
2450+ }
2451+ w. write_str ( "}" ) ?;
24432452 }
2444- w. push_str ( "}" ) ;
2445- }
2446- Some ( CtorKind :: Fn ) => {
2447- w. push_str ( "(" ) ;
2448- if !fields. is_empty ( )
2449- && fields. iter ( ) . all ( |field| {
2450- matches ! ( field. kind, clean:: StrippedItem ( box clean:: StructFieldItem ( ..) ) )
2451- } )
2452- {
2453- write_str ( w, format_args ! ( "<span class=\" comment\" >/* private fields */</span>" ) ) ;
2454- } else {
2455- for ( i, field) in fields. iter ( ) . enumerate ( ) {
2456- if i > 0 {
2457- w. push_str ( ", " ) ;
2458- }
2459- match field. kind {
2460- clean:: StrippedItem ( box clean:: StructFieldItem ( ..) ) => {
2461- write_str ( w, format_args ! ( "_" ) ) ;
2453+ Some ( CtorKind :: Fn ) => {
2454+ w. write_str ( "(" ) ?;
2455+ if !fields. is_empty ( )
2456+ && fields. iter ( ) . all ( |field| {
2457+ matches ! ( field. kind, clean:: StrippedItem ( box clean:: StructFieldItem ( ..) ) )
2458+ } )
2459+ {
2460+ write ! ( w, "<span class=\" comment\" >/* private fields */</span>" ) ?;
2461+ } else {
2462+ for ( i, field) in fields. iter ( ) . enumerate ( ) {
2463+ if i > 0 {
2464+ w. write_str ( ", " ) ?;
24622465 }
2463- clean:: StructFieldItem ( ref ty) => {
2464- write_str (
2465- w,
2466- format_args ! (
2466+ match field. kind {
2467+ clean:: StrippedItem ( box clean:: StructFieldItem ( ..) ) => {
2468+ write ! ( w, "_" ) ?;
2469+ }
2470+ clean:: StructFieldItem ( ref ty) => {
2471+ write ! (
2472+ w,
24672473 "{}{}" ,
24682474 visibility_print_with_space( field, cx) ,
24692475 ty. print( cx)
2470- ) ,
2471- ) ;
2476+ ) ?;
2477+ }
2478+ _ => unreachable ! ( ) ,
24722479 }
2473- _ => unreachable ! ( ) ,
24742480 }
24752481 }
2476- }
2477- w. push_str ( ")" ) ;
2478- if let Some ( g) = g {
2479- write_str (
2480- w,
2481- format_args ! (
2482+ w. write_str ( ")" ) ?;
2483+ if let Some ( g) = g {
2484+ write ! (
2485+ w,
24822486 "{}" ,
24832487 print_where_clause( g, cx, 0 , Ending :: NoNewline ) . maybe_display( )
2484- ) ,
2485- ) ;
2486- }
2487- // We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
2488- if structhead {
2489- w . push_str ( ";" ) ;
2488+ ) ? ;
2489+ }
2490+ // We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
2491+ if structhead {
2492+ w . write_str ( ";" ) ? ;
2493+ }
24902494 }
2491- }
2492- Some ( CtorKind :: Const ) => {
2493- // Needed for PhantomData.
2494- if let Some ( g) = g {
2495- write_str (
2496- w,
2497- format_args ! (
2495+ Some ( CtorKind :: Const ) => {
2496+ // Needed for PhantomData.
2497+ if let Some ( g) = g {
2498+ write ! (
2499+ w,
24982500 "{}" ,
24992501 print_where_clause( g, cx, 0 , Ending :: NoNewline ) . maybe_display( )
2500- ) ,
2501- ) ;
2502+ ) ?;
2503+ }
2504+ w. write_str ( ";" ) ?;
25022505 }
2503- w. push_str ( ";" ) ;
25042506 }
2505- }
2507+ Ok ( ( ) )
2508+ } )
25062509}
25072510
25082511fn document_non_exhaustive_header ( item : & clean:: Item ) -> & str {
0 commit comments