@@ -29,7 +29,7 @@ use tracing::{debug, trace};
29
29
use super :: url_parts_builder:: UrlPartsBuilder ;
30
30
use crate :: clean:: types:: ExternalLocation ;
31
31
use crate :: clean:: utils:: find_nearest_parent_module;
32
- use crate :: clean:: { self , ExternalCrate , PrimitiveType } ;
32
+ use crate :: clean:: { self , ExternalCrate , Parameter , PrimitiveType } ;
33
33
use crate :: display:: { Joined as _, MaybeDisplay as _} ;
34
34
use crate :: formats:: cache:: Cache ;
35
35
use crate :: formats:: item_type:: ItemType ;
@@ -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 {
@@ -1325,40 +1326,21 @@ impl clean::FnDecl {
1325
1326
} )
1326
1327
}
1327
1328
1328
- fn inner_full_print (
1329
- & self ,
1330
- // For None, the declaration will not be line-wrapped. For Some(n),
1331
- // the declaration will be line-wrapped, with an indent of n spaces.
1332
- line_wrapping_indent : Option < usize > ,
1333
- f : & mut fmt:: Formatter < ' _ > ,
1334
- cx : & Context < ' _ > ,
1335
- ) -> fmt:: Result {
1336
- let amp = if f. alternate ( ) { "&" } else { "&" } ;
1337
-
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
- }
1344
-
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
- }
1329
+ fn print_param ( param : & Parameter , cx : & Context < ' _ > ) -> impl fmt:: Display {
1330
+ fmt:: from_fn ( move |f| {
1331
+ if let Some ( self_ty) = param. to_receiver ( ) {
1332
+ match self_ty {
1333
+ clean:: SelfTy => f. write_str ( "self" ) ,
1352
1334
clean:: BorrowedRef { lifetime, mutability, type_ : box clean:: SelfTy } => {
1353
- write ! ( f , "{ amp}" ) ?;
1335
+ f . write_str ( if f . alternate ( ) { "&" } else { "& amp;" } ) ?;
1354
1336
if let Some ( lt) = lifetime {
1355
1337
write ! ( f, "{lt} " , lt = lt. print( ) ) ?;
1356
1338
}
1357
- write ! ( f, "{mutability}self" , mutability = mutability. print_with_space( ) ) ? ;
1339
+ write ! ( f, "{mutability}self" , mutability = mutability. print_with_space( ) )
1358
1340
}
1359
1341
_ => {
1360
- write ! ( f , "self: " ) ?;
1361
- selfty . print ( cx) . fmt ( f) ? ;
1342
+ f . write_str ( "self: " ) ?;
1343
+ self_ty . print ( cx) . fmt ( f)
1362
1344
}
1363
1345
}
1364
1346
} else {
@@ -1368,28 +1350,59 @@ impl clean::FnDecl {
1368
1350
if let Some ( name) = param. name {
1369
1351
write ! ( f, "{name}: " ) ?;
1370
1352
}
1371
- param. type_ . print ( cx) . fmt ( f) ?;
1353
+ param. type_ . print ( cx) . fmt ( f)
1354
+ }
1355
+ } )
1356
+ }
1357
+
1358
+ fn inner_full_print (
1359
+ & self ,
1360
+ // For None, the declaration will not be line-wrapped. For Some(n),
1361
+ // the declaration will be line-wrapped, with an indent of n spaces.
1362
+ line_wrapping_indent : Option < usize > ,
1363
+ f : & mut fmt:: Formatter < ' _ > ,
1364
+ cx : & Context < ' _ > ,
1365
+ ) -> fmt:: Result {
1366
+ f. write_char ( '(' ) ?;
1367
+
1368
+ if !self . inputs . is_empty ( ) {
1369
+ if self . inputs . is_empty ( ) {
1370
+ return Ok ( ( ) ) ;
1371
+ }
1372
+
1373
+ let line_wrapping_indent = line_wrapping_indent. map ( |n| Indent ( n + 4 ) ) ;
1374
+
1375
+ if let Some ( indent) = line_wrapping_indent {
1376
+ write ! ( f, "\n {indent}" ) ?;
1377
+ }
1378
+
1379
+ let sep = fmt:: from_fn ( |f| {
1380
+ if let Some ( indent) = line_wrapping_indent {
1381
+ write ! ( f, ",\n {indent}" )
1382
+ } else {
1383
+ f. write_str ( ", " )
1384
+ }
1385
+ } ) ;
1386
+
1387
+ self . inputs . iter ( ) . map ( |param| Self :: print_param ( param, cx) ) . joined ( sep, f) ?;
1388
+
1389
+ if line_wrapping_indent. is_some ( ) {
1390
+ writeln ! ( f, "," ) ?
1372
1391
}
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 , "," ) ? ,
1392
+
1393
+ if self . c_variadic {
1394
+ match line_wrapping_indent {
1395
+ None => write ! ( f , ", ..." ) ? ,
1396
+ Some ( indent ) => writeln ! ( f, "{indent}..." ) ?,
1397
+ } ;
1379
1398
}
1380
1399
}
1381
1400
1382
- if self . c_variadic {
1383
- match line_wrapping_indent {
1384
- None => write ! ( f, ", ..." ) ?,
1385
- Some ( n) => writeln ! ( f, "{}..." , Indent ( n + 4 ) ) ?,
1386
- } ;
1401
+ if let Some ( n) = line_wrapping_indent {
1402
+ write ! ( f, "{}" , Indent ( n) ) ?
1387
1403
}
1388
1404
1389
- match line_wrapping_indent {
1390
- None => write ! ( f, ")" ) ?,
1391
- Some ( n) => write ! ( f, "{})" , Indent ( n) ) ?,
1392
- } ;
1405
+ f. write_char ( ')' ) ?;
1393
1406
1394
1407
self . print_output ( cx) . fmt ( f)
1395
1408
}
0 commit comments