@@ -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,55 @@ 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)
1372
1354
}
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, "," ) ?,
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
+ let line_wrapping_indent = line_wrapping_indent. map ( |n| Indent ( n + 4 ) ) ;
1370
+
1371
+ if let Some ( indent) = line_wrapping_indent {
1372
+ write ! ( f, "\n {indent}" ) ?;
1373
+ }
1374
+
1375
+ let sep = fmt:: from_fn ( |f| {
1376
+ if let Some ( indent) = line_wrapping_indent {
1377
+ write ! ( f, ",\n {indent}" )
1378
+ } else {
1379
+ f. write_str ( ", " )
1380
+ }
1381
+ } ) ;
1382
+
1383
+ self . inputs . iter ( ) . map ( |param| Self :: print_param ( param, cx) ) . joined ( sep, f) ?;
1384
+
1385
+ if line_wrapping_indent. is_some ( ) {
1386
+ writeln ! ( f, "," ) ?
1387
+ }
1388
+
1389
+ if self . c_variadic {
1390
+ match line_wrapping_indent {
1391
+ None => write ! ( f, ", ..." ) ?,
1392
+ Some ( indent) => writeln ! ( f, "{indent}..." ) ?,
1393
+ } ;
1379
1394
}
1380
1395
}
1381
1396
1382
- if self . c_variadic {
1383
- match line_wrapping_indent {
1384
- None => write ! ( f, ", ..." ) ?,
1385
- Some ( n) => writeln ! ( f, "{}..." , Indent ( n + 4 ) ) ?,
1386
- } ;
1397
+ if let Some ( n) = line_wrapping_indent {
1398
+ write ! ( f, "{}" , Indent ( n) ) ?
1387
1399
}
1388
1400
1389
- match line_wrapping_indent {
1390
- None => write ! ( f, ")" ) ?,
1391
- Some ( n) => write ! ( f, "{})" , Indent ( n) ) ?,
1392
- } ;
1401
+ f. write_char ( ')' ) ?;
1393
1402
1394
1403
self . print_output ( cx) . fmt ( f)
1395
1404
}
0 commit comments