@@ -1264,6 +1264,7 @@ impl std::fmt::Write for WriteCounter {
1264
1264
}
1265
1265
1266
1266
// Implements Display by emitting the given number of spaces.
1267
+ #[ derive( Clone , Copy ) ]
1267
1268
struct Indent ( usize ) ;
1268
1269
1269
1270
impl Display for Indent {
@@ -1275,6 +1276,37 @@ impl Display for Indent {
1275
1276
}
1276
1277
}
1277
1278
1279
+ impl clean:: Parameter {
1280
+ fn print ( & self , cx : & Context < ' _ > ) -> impl fmt:: Display {
1281
+ fmt:: from_fn ( move |f| {
1282
+ if let Some ( self_ty) = self . to_receiver ( ) {
1283
+ match self_ty {
1284
+ clean:: SelfTy => f. write_str ( "self" ) ,
1285
+ clean:: BorrowedRef { lifetime, mutability, type_ : box clean:: SelfTy } => {
1286
+ f. write_str ( if f. alternate ( ) { "&" } else { "&" } ) ?;
1287
+ if let Some ( lt) = lifetime {
1288
+ write ! ( f, "{lt} " , lt = lt. print( ) ) ?;
1289
+ }
1290
+ write ! ( f, "{mutability}self" , mutability = mutability. print_with_space( ) )
1291
+ }
1292
+ _ => {
1293
+ f. write_str ( "self: " ) ?;
1294
+ self_ty. print ( cx) . fmt ( f)
1295
+ }
1296
+ }
1297
+ } else {
1298
+ if self . is_const {
1299
+ write ! ( f, "const " ) ?;
1300
+ }
1301
+ if let Some ( name) = self . name {
1302
+ write ! ( f, "{name}: " ) ?;
1303
+ }
1304
+ self . type_ . print ( cx) . fmt ( f)
1305
+ }
1306
+ } )
1307
+ }
1308
+ }
1309
+
1278
1310
impl clean:: FnDecl {
1279
1311
pub ( crate ) fn print ( & self , cx : & Context < ' _ > ) -> impl Display {
1280
1312
fmt:: from_fn ( move |f| {
@@ -1333,63 +1365,42 @@ impl clean::FnDecl {
1333
1365
f : & mut fmt:: Formatter < ' _ > ,
1334
1366
cx : & Context < ' _ > ,
1335
1367
) -> fmt:: Result {
1336
- let amp = if f . alternate ( ) { "&" } else { "&" } ;
1368
+ f . write_char ( '(' ) ? ;
1337
1369
1338
- write ! ( f, "(" ) ?;
1339
- if let Some ( n) = line_wrapping_indent
1340
- && !self . inputs . is_empty ( )
1341
- {
1342
- write ! ( f, "\n {}" , Indent ( n + 4 ) ) ?;
1343
- }
1370
+ if !self . inputs . is_empty ( ) {
1371
+ let line_wrapping_indent = line_wrapping_indent. map ( |n| Indent ( n + 4 ) ) ;
1344
1372
1345
- let last_input_index = self . inputs . len ( ) . checked_sub ( 1 ) ;
1346
- for ( i, param) in self . inputs . iter ( ) . enumerate ( ) {
1347
- if let Some ( selfty) = param. to_receiver ( ) {
1348
- match selfty {
1349
- clean:: SelfTy => {
1350
- write ! ( f, "self" ) ?;
1351
- }
1352
- clean:: BorrowedRef { lifetime, mutability, type_ : box clean:: SelfTy } => {
1353
- write ! ( f, "{amp}" ) ?;
1354
- if let Some ( lt) = lifetime {
1355
- write ! ( f, "{lt} " , lt = lt. print( ) ) ?;
1356
- }
1357
- write ! ( f, "{mutability}self" , mutability = mutability. print_with_space( ) ) ?;
1358
- }
1359
- _ => {
1360
- write ! ( f, "self: " ) ?;
1361
- selfty. print ( cx) . fmt ( f) ?;
1362
- }
1363
- }
1364
- } else {
1365
- if param. is_const {
1366
- write ! ( f, "const " ) ?;
1367
- }
1368
- if let Some ( name) = param. name {
1369
- write ! ( f, "{name}: " ) ?;
1373
+ if let Some ( indent) = line_wrapping_indent {
1374
+ write ! ( f, "\n {indent}" ) ?;
1375
+ }
1376
+
1377
+ let sep = fmt:: from_fn ( |f| {
1378
+ if let Some ( indent) = line_wrapping_indent {
1379
+ write ! ( f, ",\n {indent}" )
1380
+ } else {
1381
+ f. write_str ( ", " )
1370
1382
}
1371
- param. type_ . print ( cx) . fmt ( f) ?;
1383
+ } ) ;
1384
+
1385
+ self . inputs . iter ( ) . map ( |param| param. print ( cx) ) . joined ( sep, f) ?;
1386
+
1387
+ if line_wrapping_indent. is_some ( ) {
1388
+ writeln ! ( f, "," ) ?
1372
1389
}
1373
- match ( line_wrapping_indent , last_input_index ) {
1374
- ( _ , None ) => ( ) ,
1375
- ( None , Some ( last_i ) ) if i != last_i => write ! ( f , ", " ) ? ,
1376
- ( None , Some ( _ ) ) => ( ) ,
1377
- ( Some ( n ) , Some ( last_i ) ) if i != last_i => write ! ( f, ", \n {}" , Indent ( n + 4 ) ) ?,
1378
- ( Some ( _ ) , Some ( _ ) ) => writeln ! ( f , "," ) ? ,
1390
+
1391
+ if self . c_variadic {
1392
+ match line_wrapping_indent {
1393
+ None => write ! ( f , ", ..." ) ? ,
1394
+ Some ( indent ) => writeln ! ( f, "{indent}..." ) ?,
1395
+ } ;
1379
1396
}
1380
1397
}
1381
1398
1382
- if self . c_variadic {
1383
- match line_wrapping_indent {
1384
- None => write ! ( f, ", ..." ) ?,
1385
- Some ( n) => writeln ! ( f, "{}..." , Indent ( n + 4 ) ) ?,
1386
- } ;
1399
+ if let Some ( n) = line_wrapping_indent {
1400
+ write ! ( f, "{}" , Indent ( n) ) ?
1387
1401
}
1388
1402
1389
- match line_wrapping_indent {
1390
- None => write ! ( f, ")" ) ?,
1391
- Some ( n) => write ! ( f, "{})" , Indent ( n) ) ?,
1392
- } ;
1403
+ f. write_char ( ')' ) ?;
1393
1404
1394
1405
self . print_output ( cx) . fmt ( f)
1395
1406
}
0 commit comments