@@ -335,8 +335,6 @@ pub fn rewrite_macro_def(
335
335
result += & args;
336
336
}
337
337
338
- result += " {\n " ;
339
-
340
338
// The macro body is the most interesting part. It might end up as various
341
339
// AST nodes, but also has special variables (e.g, `$foo`) which can't be
342
340
// parsed as regular Rust code (and note that these can be escaped using
@@ -346,13 +344,23 @@ pub fn rewrite_macro_def(
346
344
let old_body = context. snippet ( branch. body ) . trim ( ) ;
347
345
let ( body_str, substs) = replace_names ( old_body) ;
348
346
349
- // We'll hack the indent below, take this into account when formatting,
350
347
let mut config = context. config . clone ( ) ;
351
- let body_indent = mac_indent. block_indent ( & config) ;
352
- let new_width = config. max_width ( ) - body_indent. width ( ) ;
353
- config. set ( ) . max_width ( new_width) ;
354
348
config. set ( ) . hide_parse_errors ( true ) ;
355
349
350
+ result += " {" ;
351
+
352
+ let has_block_body = old_body. starts_with ( "{" ) ;
353
+
354
+ let body_indent = if has_block_body {
355
+ mac_indent
356
+ } else {
357
+ // We'll hack the indent below, take this into account when formatting,
358
+ let body_indent = mac_indent. block_indent ( & config) ;
359
+ let new_width = config. max_width ( ) - body_indent. width ( ) ;
360
+ config. set ( ) . max_width ( new_width) ;
361
+ body_indent
362
+ } ;
363
+
356
364
// First try to format as items, then as statements.
357
365
let new_body = match :: format_snippet ( & body_str, & config) {
358
366
Some ( new_body) => new_body,
@@ -387,9 +395,14 @@ pub fn rewrite_macro_def(
387
395
new_body = new_body. replace ( new, old) ;
388
396
}
389
397
390
- result += & new_body;
398
+ if has_block_body {
399
+ result += new_body. trim ( ) ;
400
+ } else {
401
+ result += "\n " ;
402
+ result += & new_body;
403
+ result += & mac_indent_str;
404
+ }
391
405
392
- result += & mac_indent_str;
393
406
result += "}" ;
394
407
if def. legacy {
395
408
result += ";" ;
0 commit comments