@@ -143,11 +143,14 @@ impl Buffer {
143
143
}
144
144
}
145
145
146
- fn comma_sep < T : fmt:: Display > ( items : impl Iterator < Item = T > ) -> impl fmt:: Display {
146
+ fn comma_sep < T : fmt:: Display > (
147
+ items : impl Iterator < Item = T > ,
148
+ space_after_comma : bool ,
149
+ ) -> impl fmt:: Display {
147
150
display_fn ( move |f| {
148
151
for ( i, item) in items. enumerate ( ) {
149
152
if i != 0 {
150
- write ! ( f, ", " ) ?;
153
+ write ! ( f, ",{}" , if space_after_comma { " " } else { "" } ) ?;
151
154
}
152
155
fmt:: Display :: fmt ( & item, f) ?;
153
156
}
@@ -248,9 +251,9 @@ impl clean::Generics {
248
251
}
249
252
250
253
if f. alternate ( ) {
251
- write ! ( f, "<{:#}>" , comma_sep( real_params. map( |g| g. print( cx) ) ) )
254
+ write ! ( f, "<{:#}>" , comma_sep( real_params. map( |g| g. print( cx) ) , true ) )
252
255
} else {
253
- write ! ( f, "<{}>" , comma_sep( real_params. map( |g| g. print( cx) ) ) )
256
+ write ! ( f, "<{}>" , comma_sep( real_params. map( |g| g. print( cx) ) , true ) )
254
257
}
255
258
} )
256
259
}
@@ -266,10 +269,80 @@ crate fn print_where_clause<'a, 'tcx: 'a>(
266
269
end_newline : bool ,
267
270
) -> impl fmt:: Display + ' a + Captures < ' tcx > {
268
271
display_fn ( move |f| {
269
- if gens. where_predicates . is_empty ( ) {
272
+ let mut where_predicates = gens. where_predicates . iter ( ) . filter ( |pred| {
273
+ !matches ! ( pred, clean:: WherePredicate :: BoundPredicate { bounds, .. } if bounds. is_empty( ) )
274
+ } ) . map ( |pred| {
275
+ display_fn ( move |f| {
276
+ if f. alternate ( ) {
277
+ f. write_str ( " " ) ?;
278
+ } else {
279
+ f. write_str ( "<br>" ) ?;
280
+ }
281
+
282
+ match pred {
283
+ clean:: WherePredicate :: BoundPredicate { ty, bounds, bound_params } => {
284
+ let bounds = bounds;
285
+ let for_prefix = if bound_params. is_empty ( ) {
286
+ String :: new ( )
287
+ } else if f. alternate ( ) {
288
+ format ! (
289
+ "for<{:#}> " ,
290
+ comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) , true )
291
+ )
292
+ } else {
293
+ format ! (
294
+ "for<{}> " ,
295
+ comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) , true )
296
+ )
297
+ } ;
298
+
299
+ if f. alternate ( ) {
300
+ write ! (
301
+ f,
302
+ "{}{:#}: {:#}" ,
303
+ for_prefix,
304
+ ty. print( cx) ,
305
+ print_generic_bounds( bounds, cx)
306
+ )
307
+ } else {
308
+ write ! (
309
+ f,
310
+ "{}{}: {}" ,
311
+ for_prefix,
312
+ ty. print( cx) ,
313
+ print_generic_bounds( bounds, cx)
314
+ )
315
+ }
316
+ }
317
+ clean:: WherePredicate :: RegionPredicate { lifetime, bounds } => {
318
+ write ! (
319
+ f,
320
+ "{}: {}" ,
321
+ lifetime. print( ) ,
322
+ bounds
323
+ . iter( )
324
+ . map( |b| b. print( cx) . to_string( ) )
325
+ . collect:: <Vec <_>>( )
326
+ . join( " + " )
327
+ )
328
+ }
329
+ clean:: WherePredicate :: EqPredicate { lhs, rhs } => {
330
+ if f. alternate ( ) {
331
+ write ! ( f, "{:#} == {:#}" , lhs. print( cx) , rhs. print( cx) , )
332
+ } else {
333
+ write ! ( f, "{} == {}" , lhs. print( cx) , rhs. print( cx) , )
334
+ }
335
+ }
336
+ }
337
+ } )
338
+ } ) . peekable ( ) ;
339
+
340
+ if where_predicates. peek ( ) . is_none ( ) {
270
341
return Ok ( ( ) ) ;
271
342
}
343
+
272
344
let mut clause = String :: new ( ) ;
345
+
273
346
if f. alternate ( ) {
274
347
clause. push_str ( " where" ) ;
275
348
} else {
@@ -279,72 +352,11 @@ crate fn print_where_clause<'a, 'tcx: 'a>(
279
352
clause. push_str ( " <span class=\" where\" >where" ) ;
280
353
}
281
354
}
282
- for ( i, pred) in gens. where_predicates . iter ( ) . enumerate ( ) {
283
- if f. alternate ( ) {
284
- clause. push ( ' ' ) ;
285
- } else {
286
- clause. push_str ( "<br>" ) ;
287
- }
288
-
289
- match pred {
290
- clean:: WherePredicate :: BoundPredicate { ty, bounds, bound_params } => {
291
- let bounds = bounds;
292
- let for_prefix = match bound_params. len ( ) {
293
- 0 => String :: new ( ) ,
294
- _ if f. alternate ( ) => {
295
- format ! (
296
- "for<{:#}> " ,
297
- comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) )
298
- )
299
- }
300
- _ => format ! (
301
- "for<{}> " ,
302
- comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) )
303
- ) ,
304
- } ;
305
-
306
- if f. alternate ( ) {
307
- clause. push_str ( & format ! (
308
- "{}{:#}: {:#}" ,
309
- for_prefix,
310
- ty. print( cx) ,
311
- print_generic_bounds( bounds, cx)
312
- ) ) ;
313
- } else {
314
- clause. push_str ( & format ! (
315
- "{}{}: {}" ,
316
- for_prefix,
317
- ty. print( cx) ,
318
- print_generic_bounds( bounds, cx)
319
- ) ) ;
320
- }
321
- }
322
- clean:: WherePredicate :: RegionPredicate { lifetime, bounds } => {
323
- clause. push_str ( & format ! (
324
- "{}: {}" ,
325
- lifetime. print( ) ,
326
- bounds
327
- . iter( )
328
- . map( |b| b. print( cx) . to_string( ) )
329
- . collect:: <Vec <_>>( )
330
- . join( " + " )
331
- ) ) ;
332
- }
333
- clean:: WherePredicate :: EqPredicate { lhs, rhs } => {
334
- if f. alternate ( ) {
335
- clause. push_str ( & format ! ( "{:#} == {:#}" , lhs. print( cx) , rhs. print( cx) , ) ) ;
336
- } else {
337
- clause. push_str ( & format ! ( "{} == {}" , lhs. print( cx) , rhs. print( cx) , ) ) ;
338
- }
339
- }
340
- }
341
355
342
- if i < gens. where_predicates . len ( ) - 1 || end_newline {
343
- clause. push ( ',' ) ;
344
- }
345
- }
356
+ clause. push_str ( & comma_sep ( where_predicates, false ) . to_string ( ) ) ;
346
357
347
358
if end_newline {
359
+ clause. push ( ',' ) ;
348
360
// add a space so stripping <br> tags and breaking spaces still renders properly
349
361
if f. alternate ( ) {
350
362
clause. push ( ' ' ) ;
@@ -394,13 +406,13 @@ impl clean::PolyTrait {
394
406
write ! (
395
407
f,
396
408
"for<{:#}> " ,
397
- comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) )
409
+ comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) , true )
398
410
) ?;
399
411
} else {
400
412
write ! (
401
413
f,
402
414
"for<{}> " ,
403
- comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) )
415
+ comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) , true )
404
416
) ?;
405
417
}
406
418
}
@@ -424,7 +436,8 @@ impl clean::GenericBound {
424
436
let modifier_str = match modifier {
425
437
hir:: TraitBoundModifier :: None => "" ,
426
438
hir:: TraitBoundModifier :: Maybe => "?" ,
427
- hir:: TraitBoundModifier :: MaybeConst => "~const" ,
439
+ // ~const is experimental; do not display those bounds in rustdoc
440
+ hir:: TraitBoundModifier :: MaybeConst => "" ,
428
441
} ;
429
442
if f. alternate ( ) {
430
443
write ! ( f, "{}{:#}" , modifier_str, ty. print( cx) )
@@ -1111,7 +1124,7 @@ impl clean::BareFunctionDecl {
1111
1124
write ! (
1112
1125
f,
1113
1126
"for<{}> " ,
1114
- comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) )
1127
+ comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) , true )
1115
1128
)
1116
1129
} else {
1117
1130
Ok ( ( ) )
0 commit comments