@@ -318,7 +318,10 @@ pub fn rewrite_macro_def(
318
318
// variables for new names with the same length first.
319
319
320
320
let old_body = context. snippet ( branch. body ) . trim ( ) ;
321
- let ( body_str, substs) = replace_names ( old_body) ;
321
+ let ( body_str, substs) = match replace_names ( old_body) {
322
+ Some ( result) => result,
323
+ None => return snippet,
324
+ } ;
322
325
323
326
// We'll hack the indent below, take this into account when formatting,
324
327
let mut config = context. config . clone ( ) ;
@@ -377,7 +380,7 @@ pub fn rewrite_macro_def(
377
380
// Replaces `$foo` with `zfoo`. We must check for name overlap to ensure we
378
381
// aren't causing problems.
379
382
// This should also work for escaped `$` variables, where we leave earlier `$`s.
380
- fn replace_names ( input : & str ) -> ( String , HashMap < String , String > ) {
383
+ fn replace_names ( input : & str ) -> Option < ( String , HashMap < String , String > ) > {
381
384
// Each substitution will require five or six extra bytes.
382
385
let mut result = String :: with_capacity ( input. len ( ) + 64 ) ;
383
386
let mut substs = HashMap :: new ( ) ;
@@ -409,6 +412,9 @@ fn replace_names(input: &str) -> (String, HashMap<String, String>) {
409
412
410
413
dollar_count = 0 ;
411
414
cur_name = String :: new ( ) ;
415
+ } else if c == '(' && cur_name. is_empty ( ) {
416
+ // FIXME: Support macro def with repeat.
417
+ return None ;
412
418
} else if c. is_alphanumeric ( ) {
413
419
cur_name. push ( c) ;
414
420
}
@@ -433,7 +439,7 @@ fn replace_names(input: &str) -> (String, HashMap<String, String>) {
433
439
434
440
debug ! ( "replace_names `{}` {:?}" , result, substs) ;
435
441
436
- ( result, substs)
442
+ Some ( ( result, substs) )
437
443
}
438
444
439
445
// This is a bit sketchy. The token rules probably need tweaking, but it works
0 commit comments