@@ -44,6 +44,7 @@ use shape::{Indent, Shape};
44
44
use source_map:: SpanUtils ;
45
45
use spanned:: Spanned ;
46
46
use utils:: { format_visibility, mk_sp, rewrite_ident, wrap_str} ;
47
+ use visitor:: FmtVisitor ;
47
48
48
49
const FORCED_BRACKET_MACROS : & [ & str ] = & [ "vec!" ] ;
49
50
@@ -271,6 +272,24 @@ pub fn rewrite_macro_inner(
271
272
}
272
273
}
273
274
275
+ if !arg_vec. is_empty ( ) && arg_vec. iter ( ) . all ( |arg| {
276
+ if let MacroArg :: Item ( ..) = arg {
277
+ true
278
+ } else {
279
+ false
280
+ }
281
+ } ) {
282
+ return rewrite_macro_with_items (
283
+ context,
284
+ & arg_vec,
285
+ & macro_name,
286
+ shape,
287
+ style,
288
+ position,
289
+ mac. span ,
290
+ ) ;
291
+ }
292
+
274
293
match style {
275
294
DelimToken :: Paren => {
276
295
// Format macro invocation as function call, preserve the trailing
@@ -1428,3 +1447,45 @@ fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream)
1428
1447
1429
1448
Some ( result)
1430
1449
}
1450
+
1451
+ fn rewrite_macro_with_items(
1452
+ context: & RewriteContext ,
1453
+ items: & [ MacroArg ] ,
1454
+ macro_name: & str,
1455
+ shape: Shape ,
1456
+ style: DelimToken ,
1457
+ position: MacroPosition ,
1458
+ span: Span ,
1459
+ ) -> Option <String > {
1460
+ let ( opener, closer) = match style {
1461
+ DelimToken :: Paren => ( "(" , ")" ) ,
1462
+ DelimToken :: Bracket => ( "[" , "]" ) ,
1463
+ DelimToken :: Brace => ( " {" , "}" ) ,
1464
+ _ => return None ,
1465
+ } ;
1466
+ let trailing_semicolon = match style {
1467
+ DelimToken :: Paren | DelimToken :: Bracket if position == MacroPosition :: Item => ";" ,
1468
+ _ => "" ,
1469
+ } ;
1470
+
1471
+ let mut visitor = FmtVisitor :: from_context ( context) ;
1472
+ visitor. block_indent = shape. indent . block_indent ( context. config ) ;
1473
+ visitor. last_pos = context. snippet_provider . span_after ( span, opener. trim ( ) ) ;
1474
+ for item in items {
1475
+ let item = match item {
1476
+ MacroArg :: Item ( item) => item,
1477
+ _ => return None ,
1478
+ } ;
1479
+ visitor. visit_item ( & item) ;
1480
+ }
1481
+
1482
+ let mut result = String :: with_capacity ( 256 ) ;
1483
+ result. push_str ( & macro_name) ;
1484
+ result. push_str ( opener) ;
1485
+ result. push_str ( & visitor. block_indent . to_string_with_newline ( context. config ) ) ;
1486
+ result. push_str ( visitor. buffer . trim ( ) ) ;
1487
+ result. push_str ( & shape. indent . to_string_with_newline ( context. config ) ) ;
1488
+ result. push_str ( closer) ;
1489
+ result. push_str ( trailing_semicolon) ;
1490
+ return Some ( result) ;
1491
+ }
0 commit comments