@@ -162,17 +162,6 @@ struct ItemVars<'a> {
162
162
src_href : Option < & ' a str > ,
163
163
}
164
164
165
- /// Calls `print_where_clause` and returns `true` if a `where` clause was generated.
166
- fn print_where_clause_and_check < ' a , ' tcx : ' a > (
167
- buffer : & mut String ,
168
- gens : & ' a clean:: Generics ,
169
- cx : & ' a Context < ' tcx > ,
170
- ) -> bool {
171
- let len_before = buffer. len ( ) ;
172
- write_str ( buffer, format_args ! ( "{}" , print_where_clause( gens, cx, 0 , Ending :: Newline ) ) ) ;
173
- len_before != buffer. len ( )
174
- }
175
-
176
165
pub ( super ) fn print_item ( cx : & Context < ' _ > , item : & clean:: Item , buf : & mut String ) {
177
166
debug_assert ! ( !item. is_stripped( ) ) ;
178
167
let typ = match item. kind {
@@ -638,7 +627,8 @@ fn item_function<'a, 'tcx>(
638
627
abi = abi,
639
628
name = name,
640
629
generics = f. generics. print( cx) ,
641
- where_clause = print_where_clause( & f. generics, cx, 0 , Ending :: Newline ) ,
630
+ where_clause =
631
+ print_where_clause( & f. generics, cx, 0 , Ending :: Newline ) . maybe_display( ) ,
642
632
decl = f. decl. full_print( header_len, 0 , cx) ,
643
633
)
644
634
} ) ?;
@@ -682,7 +672,11 @@ fn item_trait<'a, 'tcx>(
682
672
) ?;
683
673
684
674
if !t. generics . where_predicates . is_empty ( ) {
685
- write ! ( w, "{}" , print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) ) ?;
675
+ write ! (
676
+ w,
677
+ "{}" ,
678
+ print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) . maybe_display( )
679
+ ) ?;
686
680
} else {
687
681
w. write_char ( ' ' ) ?;
688
682
}
@@ -1252,7 +1246,7 @@ fn item_trait_alias(
1252
1246
attrs = render_attributes_in_pre( it, "" , cx) ,
1253
1247
name = it. name. unwrap( ) ,
1254
1248
generics = t. generics. print( cx) ,
1255
- where_b = print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) ,
1249
+ where_b = print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) . maybe_display ( ) ,
1256
1250
bounds = bounds( & t. bounds, true , cx) ,
1257
1251
)
1258
1252
. unwrap ( ) ;
@@ -1277,7 +1271,8 @@ fn item_type_alias(w: &mut String, cx: &Context<'_>, it: &clean::Item, t: &clean
1277
1271
vis = visibility_print_with_space( it, cx) ,
1278
1272
name = it. name. unwrap( ) ,
1279
1273
generics = t. generics. print( cx) ,
1280
- where_clause = print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) ,
1274
+ where_clause =
1275
+ print_where_clause( & t. generics, cx, 0 , Ending :: Newline ) . maybe_display( ) ,
1281
1276
type_ = t. type_. print( cx) ,
1282
1277
) ,
1283
1278
) ;
@@ -1651,9 +1646,13 @@ fn render_enum_fields(
1651
1646
enum_def_id : DefId ,
1652
1647
) {
1653
1648
let should_show_enum_discriminant = should_show_enum_discriminant ( cx, enum_def_id, variants) ;
1654
- if !g. is_some_and ( |g| print_where_clause_and_check ( w, g, cx) ) {
1649
+ if let Some ( generics) = g
1650
+ && let Some ( where_clause) = print_where_clause ( generics, cx, 0 , Ending :: Newline )
1651
+ {
1652
+ write_str ( w, format_args ! ( "{where_clause}" ) ) ;
1653
+ } else {
1655
1654
// If there wasn't a `where` clause, we add a whitespace.
1656
- w. push_str ( " " ) ;
1655
+ w. push ( ' ' )
1657
1656
}
1658
1657
1659
1658
let variants_stripped = has_stripped_entries;
@@ -1930,7 +1929,8 @@ fn item_constant(
1930
1929
name = it. name. unwrap( ) ,
1931
1930
generics = generics. print( cx) ,
1932
1931
typ = ty. print( cx) ,
1933
- where_clause = print_where_clause( generics, cx, 0 , Ending :: NoNewline )
1932
+ where_clause =
1933
+ print_where_clause( generics, cx, 0 , Ending :: NoNewline ) . maybe_display( ) ,
1934
1934
) ,
1935
1935
) ;
1936
1936
@@ -2295,14 +2295,17 @@ fn render_union<'a, 'cx: 'a>(
2295
2295
fmt:: from_fn ( move |mut f| {
2296
2296
write ! ( f, "{}union {}" , visibility_print_with_space( it, cx) , it. name. unwrap( ) , ) ?;
2297
2297
2298
- let where_displayed = g
2299
- . map ( |g| {
2300
- let mut buf = g. print ( cx) . to_string ( ) ;
2301
- let where_displayed = print_where_clause_and_check ( & mut buf, g, cx) ;
2302
- f. write_str ( & buf) . unwrap ( ) ;
2303
- where_displayed
2304
- } )
2305
- . unwrap_or ( false ) ;
2298
+ let where_displayed = if let Some ( generics) = g {
2299
+ write ! ( f, "{}" , generics. print( cx) ) ?;
2300
+ if let Some ( where_clause) = print_where_clause ( generics, cx, 0 , Ending :: Newline ) {
2301
+ write ! ( f, "{where_clause}" ) ?;
2302
+ true
2303
+ } else {
2304
+ false
2305
+ }
2306
+ } else {
2307
+ false
2308
+ } ;
2306
2309
2307
2310
// If there wasn't a `where` clause, we add a whitespace.
2308
2311
if !where_displayed {
@@ -2386,8 +2389,14 @@ fn render_struct_fields(
2386
2389
) {
2387
2390
match ty {
2388
2391
None => {
2389
- let where_displayed =
2390
- g. map ( |g| print_where_clause_and_check ( w, g, cx) ) . unwrap_or ( false ) ;
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
+ } ;
2391
2400
2392
2401
// If there wasn't a `where` clause, we add a whitespace.
2393
2402
if !where_displayed {
@@ -2467,7 +2476,13 @@ fn render_struct_fields(
2467
2476
}
2468
2477
w. push_str ( ")" ) ;
2469
2478
if let Some ( g) = g {
2470
- write_str ( w, format_args ! ( "{}" , print_where_clause( g, cx, 0 , Ending :: NoNewline ) ) ) ;
2479
+ write_str (
2480
+ w,
2481
+ format_args ! (
2482
+ "{}" ,
2483
+ print_where_clause( g, cx, 0 , Ending :: NoNewline ) . maybe_display( )
2484
+ ) ,
2485
+ ) ;
2471
2486
}
2472
2487
// We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
2473
2488
if structhead {
@@ -2477,7 +2492,13 @@ fn render_struct_fields(
2477
2492
Some ( CtorKind :: Const ) => {
2478
2493
// Needed for PhantomData.
2479
2494
if let Some ( g) = g {
2480
- write_str ( w, format_args ! ( "{}" , print_where_clause( g, cx, 0 , Ending :: NoNewline ) ) ) ;
2495
+ write_str (
2496
+ w,
2497
+ format_args ! (
2498
+ "{}" ,
2499
+ print_where_clause( g, cx, 0 , Ending :: NoNewline ) . maybe_display( )
2500
+ ) ,
2501
+ ) ;
2481
2502
}
2482
2503
w. push_str ( ";" ) ;
2483
2504
}
0 commit comments