File tree Expand file tree Collapse file tree 2 files changed +40
-31
lines changed Expand file tree Collapse file tree 2 files changed +40
-31
lines changed Original file line number Diff line number Diff line change @@ -305,9 +305,16 @@ pub fn rewrite_macro_def(
305
305
306
306
result += " " ;
307
307
result += & ident. name . as_str ( ) ;
308
- result += " {" ;
309
308
310
- let mac_indent = indent. block_indent ( & context. config ) ;
309
+ let multi_branch_style = def. legacy || parsed_def. branches . len ( ) != 1 ;
310
+
311
+ let mac_indent = if multi_branch_style {
312
+ result += " {" ;
313
+ indent. block_indent ( & context. config )
314
+ } else {
315
+ indent
316
+ } ;
317
+
311
318
let mac_indent_str = mac_indent. to_string ( & context. config ) ;
312
319
313
320
for branch in parsed_def. branches {
@@ -317,11 +324,18 @@ pub fn rewrite_macro_def(
317
324
return snippet;
318
325
}
319
326
320
- result += "\n " ;
321
- result += & mac_indent_str;
322
- result += "(" ;
323
- result += & format_macro_args ( branch. args ) ?;
324
- result += ") => {\n " ;
327
+ let args = format ! ( "({})" , format_macro_args( branch. args) ?) ;
328
+
329
+ if multi_branch_style {
330
+ result += "\n " ;
331
+ result += & mac_indent_str;
332
+ result += & args;
333
+ result += " =>" ;
334
+ } else {
335
+ result += & args;
336
+ }
337
+
338
+ result += " {\n " ;
325
339
326
340
// The macro body is the most interesting part. It might end up as various
327
341
// AST nodes, but also has special variables (e.g, `$foo`) which can't be
@@ -377,14 +391,16 @@ pub fn rewrite_macro_def(
377
391
378
392
result += & mac_indent_str;
379
393
result += "}" ;
380
- if def. legacy {
394
+ if def. legacy {
381
395
result += ";" ;
382
396
}
383
397
result += "\n " ;
384
398
}
385
399
386
- result += & indent. to_string ( & context. config ) ;
387
- result += "}" ;
400
+ if multi_branch_style {
401
+ result += & indent. to_string ( & context. config ) ;
402
+ result += "}" ;
403
+ }
388
404
389
405
Some ( result)
390
406
}
Original file line number Diff line number Diff line change @@ -27,9 +27,8 @@ fn main() {
27
27
) ;
28
28
29
29
kaas ! (
30
- // comments
31
- a, // post macro
32
- b // another
30
+ /* comments */ a, /* post macro */
31
+ b /* another */
33
32
) ;
34
33
35
34
trailingcomma ! ( a, b, c, ) ;
@@ -890,28 +889,22 @@ fn macro_in_pattern_position() {
890
889
} ;
891
890
}
892
891
893
- macro foo {
894
- ( ) => {
895
- }
892
+ macro foo( ) {
896
893
}
897
894
898
- pub macro bar {
899
- ( $x: ident + $y: expr; ) => {
900
- fn foo ( $x: Foo ) {
901
- long_function (
902
- a_long_argument_to_a_long_function_is_what_this_is ( AAAAAAAAAAAAAAAAAAAAAAAAAAAA ) ,
903
- $x. bar ( $y) ,
904
- ) ;
905
- }
895
+ pub macro bar ( $x: ident + $y: expr; ) {
896
+ fn foo ( $x: Foo ) {
897
+ long_function (
898
+ a_long_argument_to_a_long_function_is_what_this_is ( AAAAAAAAAAAAAAAAAAAAAAAAAAAA ) ,
899
+ $x. bar ( $y) ,
900
+ ) ;
906
901
}
907
902
}
908
903
909
- macro foo {
910
- ( ) => {
911
- // a comment
912
- fn foo ( ) {
913
- // another comment
914
- bar ( ) ;
915
- }
904
+ macro foo( ) {
905
+ // a comment
906
+ fn foo ( ) {
907
+ // another comment
908
+ bar ( ) ;
916
909
}
917
910
}
You can’t perform that action at this time.
0 commit comments