@@ -361,51 +361,35 @@ fn rewrite_macro_inner(
361
361
362
362
match style {
363
363
DelimToken :: Paren => {
364
- // Format macro invocation as function call, preserve the trailing
365
- // comma because not all macros support them.
366
- overflow:: rewrite_with_parens (
367
- context,
368
- & macro_name,
369
- arg_vec. iter ( ) ,
370
- shape,
371
- mac. span ,
372
- context. config . width_heuristics ( ) . fn_call_width ,
373
- if trailing_comma {
374
- Some ( SeparatorTactic :: Always )
375
- } else {
376
- Some ( SeparatorTactic :: Never )
377
- } ,
378
- )
379
- . map ( |rw| match position {
380
- MacroPosition :: Item => format ! ( "{};" , rw) ,
381
- _ => rw,
382
- } )
364
+ // Handle special case: `vec!(expr; expr)`
365
+ if vec_with_semi {
366
+ handle_vec_semi ( context, shape, arg_vec, macro_name, style)
367
+ } else {
368
+ // Format macro invocation as function call, preserve the trailing
369
+ // comma because not all macros support them.
370
+ overflow:: rewrite_with_parens (
371
+ context,
372
+ & macro_name,
373
+ arg_vec. iter ( ) ,
374
+ shape,
375
+ mac. span ,
376
+ context. config . width_heuristics ( ) . fn_call_width ,
377
+ if trailing_comma {
378
+ Some ( SeparatorTactic :: Always )
379
+ } else {
380
+ Some ( SeparatorTactic :: Never )
381
+ } ,
382
+ )
383
+ . map ( |rw| match position {
384
+ MacroPosition :: Item => format ! ( "{};" , rw) ,
385
+ _ => rw,
386
+ } )
387
+ }
383
388
}
384
389
DelimToken :: Bracket => {
385
390
// Handle special case: `vec![expr; expr]`
386
391
if vec_with_semi {
387
- let mac_shape = shape. offset_left ( macro_name. len ( ) ) ?;
388
- // 8 = `vec![]` + `; `
389
- let total_overhead = 8 ;
390
- let nested_shape = mac_shape. block_indent ( context. config . tab_spaces ( ) ) ;
391
- let lhs = arg_vec[ 0 ] . rewrite ( context, nested_shape) ?;
392
- let rhs = arg_vec[ 1 ] . rewrite ( context, nested_shape) ?;
393
- if !lhs. contains ( '\n' )
394
- && !rhs. contains ( '\n' )
395
- && lhs. len ( ) + rhs. len ( ) + total_overhead <= shape. width
396
- {
397
- Some ( format ! ( "{}[{}; {}]" , macro_name, lhs, rhs) )
398
- } else {
399
- Some ( format ! (
400
- "{}[{}{};{}{}{}]" ,
401
- macro_name,
402
- nested_shape. indent. to_string_with_newline( context. config) ,
403
- lhs,
404
- nested_shape. indent. to_string_with_newline( context. config) ,
405
- rhs,
406
- shape. indent. to_string_with_newline( context. config) ,
407
- ) )
408
- }
392
+ handle_vec_semi ( context, shape, arg_vec, macro_name, style)
409
393
} else {
410
394
// If we are rewriting `vec!` macro or other special macros,
411
395
// then we can rewrite this as an usual array literal.
@@ -453,6 +437,47 @@ fn rewrite_macro_inner(
453
437
}
454
438
}
455
439
440
+ fn handle_vec_semi (
441
+ context : & RewriteContext < ' _ > ,
442
+ shape : Shape ,
443
+ arg_vec : Vec < MacroArg > ,
444
+ macro_name : String ,
445
+ delim_token : DelimToken ,
446
+ ) -> Option < String > {
447
+ let ( left, right) = match delim_token {
448
+ DelimToken :: Paren => ( "(" , ")" ) ,
449
+ DelimToken :: Bracket => ( "[" , "]" ) ,
450
+ _ => unreachable ! ( ) ,
451
+ } ;
452
+
453
+ let mac_shape = shape. offset_left ( macro_name. len ( ) ) ?;
454
+ // 8 = `vec![]` + `; ` or `vec!()` + `; `
455
+ let total_overhead = 8 ;
456
+ let nested_shape = mac_shape. block_indent ( context. config . tab_spaces ( ) ) ;
457
+ let lhs = arg_vec[ 0 ] . rewrite ( context, nested_shape) ?;
458
+ let rhs = arg_vec[ 1 ] . rewrite ( context, nested_shape) ?;
459
+ if !lhs. contains ( '\n' )
460
+ && !rhs. contains ( '\n' )
461
+ && lhs. len ( ) + rhs. len ( ) + total_overhead <= shape. width
462
+ {
463
+ // macro_name(lhs; rhs) or macro_name[lhs; rhs]
464
+ Some ( format ! ( "{}{}{}; {}{}" , macro_name, left, lhs, rhs, right) )
465
+ } else {
466
+ // macro_name(\nlhs;\nrhs\n) or macro_name[\nlhs;\nrhs\n]
467
+ Some ( format ! (
468
+ "{}{}{}{};{}{}{}{}" ,
469
+ macro_name,
470
+ left,
471
+ nested_shape. indent. to_string_with_newline( context. config) ,
472
+ lhs,
473
+ nested_shape. indent. to_string_with_newline( context. config) ,
474
+ rhs,
475
+ shape. indent. to_string_with_newline( context. config) ,
476
+ right
477
+ ) )
478
+ }
479
+ }
480
+
456
481
pub ( crate ) fn rewrite_macro_def (
457
482
context : & RewriteContext < ' _ > ,
458
483
shape : Shape ,
0 commit comments