@@ -2359,6 +2359,21 @@ impl Rewrite for ast::Param {
2359
2359
}
2360
2360
}
2361
2361
2362
+ fn rewrite_opt_lifetime (
2363
+ context : & RewriteContext < ' _ > ,
2364
+ lifetime : Option < ast:: Lifetime > ,
2365
+ ) -> RewriteResult {
2366
+ let Some ( l) = lifetime else {
2367
+ return Ok ( String :: new ( ) ) ;
2368
+ } ;
2369
+ let mut result = l. rewrite_result (
2370
+ context,
2371
+ Shape :: legacy ( context. config . max_width ( ) , Indent :: empty ( ) ) ,
2372
+ ) ?;
2373
+ result. push ( ' ' ) ;
2374
+ Ok ( result)
2375
+ }
2376
+
2362
2377
fn rewrite_explicit_self (
2363
2378
context : & RewriteContext < ' _ > ,
2364
2379
explicit_self : & ast:: ExplicitSelf ,
@@ -2367,85 +2382,34 @@ fn rewrite_explicit_self(
2367
2382
shape : Shape ,
2368
2383
has_multiple_attr_lines : bool ,
2369
2384
) -> RewriteResult {
2370
- match explicit_self. node {
2385
+ let self_str = match explicit_self. node {
2371
2386
ast:: SelfKind :: Region ( lt, m) => {
2372
2387
let mut_str = format_mutability ( m) ;
2373
- match lt {
2374
- Some ( ref l) => {
2375
- let lifetime_str = l. rewrite_result (
2376
- context,
2377
- Shape :: legacy ( context. config . max_width ( ) , Indent :: empty ( ) ) ,
2378
- ) ?;
2379
- Ok ( combine_strs_with_missing_comments (
2380
- context,
2381
- param_attrs,
2382
- & format ! ( "&{lifetime_str} {mut_str}self" ) ,
2383
- span,
2384
- shape,
2385
- !has_multiple_attr_lines,
2386
- ) ?)
2387
- }
2388
- None => Ok ( combine_strs_with_missing_comments (
2389
- context,
2390
- param_attrs,
2391
- & format ! ( "&{mut_str}self" ) ,
2392
- span,
2393
- shape,
2394
- !has_multiple_attr_lines,
2395
- ) ?) ,
2396
- }
2388
+ let lifetime_str = rewrite_opt_lifetime ( context, lt) ?;
2389
+ format ! ( "&{lifetime_str}{mut_str}self" )
2397
2390
}
2398
2391
ast:: SelfKind :: Pinned ( lt, m) => {
2399
2392
let mut_str = m. ptr_str ( ) ;
2400
- match lt {
2401
- Some ( ref l) => {
2402
- let lifetime_str = l. rewrite_result (
2403
- context,
2404
- Shape :: legacy ( context. config . max_width ( ) , Indent :: empty ( ) ) ,
2405
- ) ?;
2406
- Ok ( combine_strs_with_missing_comments (
2407
- context,
2408
- param_attrs,
2409
- & format ! ( "&{lifetime_str} pin {mut_str} self" ) ,
2410
- span,
2411
- shape,
2412
- !has_multiple_attr_lines,
2413
- ) ?)
2414
- }
2415
- None => Ok ( combine_strs_with_missing_comments (
2416
- context,
2417
- param_attrs,
2418
- & format ! ( "&pin {mut_str} self" ) ,
2419
- span,
2420
- shape,
2421
- !has_multiple_attr_lines,
2422
- ) ?) ,
2423
- }
2393
+ let lifetime_str = rewrite_opt_lifetime ( context, lt) ?;
2394
+ format ! ( "&{lifetime_str}pin {mut_str} self" )
2424
2395
}
2425
2396
ast:: SelfKind :: Explicit ( ref ty, mutability) => {
2426
2397
let type_str = ty. rewrite_result (
2427
2398
context,
2428
2399
Shape :: legacy ( context. config . max_width ( ) , Indent :: empty ( ) ) ,
2429
2400
) ?;
2430
-
2431
- Ok ( combine_strs_with_missing_comments (
2432
- context,
2433
- param_attrs,
2434
- & format ! ( "{}self: {}" , format_mutability( mutability) , type_str) ,
2435
- span,
2436
- shape,
2437
- !has_multiple_attr_lines,
2438
- ) ?)
2401
+ format ! ( "{}self: {}" , format_mutability( mutability) , type_str)
2439
2402
}
2440
- ast:: SelfKind :: Value ( mutability) => Ok ( combine_strs_with_missing_comments (
2441
- context,
2442
- param_attrs,
2443
- & format ! ( "{}self" , format_mutability( mutability) ) ,
2444
- span,
2445
- shape,
2446
- !has_multiple_attr_lines,
2447
- ) ?) ,
2448
- }
2403
+ ast:: SelfKind :: Value ( mutability) => format ! ( "{}self" , format_mutability( mutability) ) ,
2404
+ } ;
2405
+ Ok ( combine_strs_with_missing_comments (
2406
+ context,
2407
+ param_attrs,
2408
+ & self_str,
2409
+ span,
2410
+ shape,
2411
+ !has_multiple_attr_lines,
2412
+ ) ?)
2449
2413
}
2450
2414
2451
2415
pub ( crate ) fn span_lo_for_param ( param : & ast:: Param ) -> BytePos {
0 commit comments