@@ -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 = match bound_params. len ( ) {
286
+ 0 => String :: new ( ) ,
287
+ _ if f. alternate ( ) => {
288
+ format ! (
289
+ "for<{:#}> " ,
290
+ comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) , true )
291
+ )
292
+ }
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 {
@@ -280,82 +353,7 @@ crate fn print_where_clause<'a, 'tcx: 'a>(
280
353
}
281
354
}
282
355
283
- #[ derive( Clone , Copy ) ]
284
- enum Print < ' a > {
285
- Predicate ( & ' a clean:: WherePredicate ) ,
286
- Comma ,
287
- }
288
-
289
- for pred in gens. where_predicates . iter ( ) . filter ( |pred| {
290
- !matches ! ( pred, clean:: WherePredicate :: BoundPredicate { bounds, .. } if bounds. is_empty( ) )
291
- } ) . map ( Print :: Predicate ) . intersperse ( Print :: Comma ) {
292
- let pred = match pred {
293
- Print :: Predicate ( pred) => pred,
294
- Print :: Comma => {
295
- clause. push ( ',' ) ;
296
- continue ;
297
- }
298
- } ;
299
-
300
- if f. alternate ( ) {
301
- clause. push ( ' ' ) ;
302
- } else {
303
- clause. push_str ( "<br>" ) ;
304
- }
305
-
306
- match pred {
307
- clean:: WherePredicate :: BoundPredicate { ty, bounds, bound_params } => {
308
- let bounds = bounds;
309
- let for_prefix = match bound_params. len ( ) {
310
- 0 => String :: new ( ) ,
311
- _ if f. alternate ( ) => {
312
- format ! (
313
- "for<{:#}> " ,
314
- comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) )
315
- )
316
- }
317
- _ => format ! (
318
- "for<{}> " ,
319
- comma_sep( bound_params. iter( ) . map( |lt| lt. print( ) ) )
320
- ) ,
321
- } ;
322
-
323
- if f. alternate ( ) {
324
- clause. push_str ( & format ! (
325
- "{}{:#}: {:#}" ,
326
- for_prefix,
327
- ty. print( cx) ,
328
- print_generic_bounds( bounds, cx)
329
- ) ) ;
330
- } else {
331
- clause. push_str ( & format ! (
332
- "{}{}: {}" ,
333
- for_prefix,
334
- ty. print( cx) ,
335
- print_generic_bounds( bounds, cx)
336
- ) ) ;
337
- }
338
- }
339
- clean:: WherePredicate :: RegionPredicate { lifetime, bounds } => {
340
- clause. push_str ( & format ! (
341
- "{}: {}" ,
342
- lifetime. print( ) ,
343
- bounds
344
- . iter( )
345
- . map( |b| b. print( cx) . to_string( ) )
346
- . collect:: <Vec <_>>( )
347
- . join( " + " )
348
- ) ) ;
349
- }
350
- clean:: WherePredicate :: EqPredicate { lhs, rhs } => {
351
- if f. alternate ( ) {
352
- clause. push_str ( & format ! ( "{:#} == {:#}" , lhs. print( cx) , rhs. print( cx) , ) ) ;
353
- } else {
354
- clause. push_str ( & format ! ( "{} == {}" , lhs. print( cx) , rhs. print( cx) , ) ) ;
355
- }
356
- }
357
- }
358
- }
356
+ clause. push_str ( & comma_sep ( where_predicates, false ) . to_string ( ) ) ;
359
357
360
358
if end_newline {
361
359
clause. push ( ',' ) ;
@@ -408,13 +406,13 @@ impl clean::PolyTrait {
408
406
write ! (
409
407
f,
410
408
"for<{:#}> " ,
411
- comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) )
409
+ comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) , true )
412
410
) ?;
413
411
} else {
414
412
write ! (
415
413
f,
416
414
"for<{}> " ,
417
- comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) )
415
+ comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) , true )
418
416
) ?;
419
417
}
420
418
}
@@ -1125,7 +1123,7 @@ impl clean::BareFunctionDecl {
1125
1123
write ! (
1126
1124
f,
1127
1125
"for<{}> " ,
1128
- comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) )
1126
+ comma_sep( self . generic_params. iter( ) . map( |g| g. print( cx) ) , true )
1129
1127
)
1130
1128
} else {
1131
1129
Ok ( ( ) )
0 commit comments