Repository: rust
Issue: Unexpected recursive decl-macro expansion
Labels: A-macros,C-bug

**Tested on:** 1.71 nightly 1c42cb4ef0544fbfaa50

The following code:

```rust

trait WithLt<'a> {
    type Output: 'a;
}

macro_rules! WithLt {
    ($($ty:tt)*) => {
        dyn for<'__lt> WithLt<'__lt, Output =
            __WithLt!([$($ty)*] [])
        >
    };
}

macro_rules! __WithLt {
    // Replace '_ with '__lt.
    (['_ $($tail:tt)*] [$($out:tt)*]) => {
        __WithLt!([$($tail)*] [$($out)* '__lt])
    };
    // Recurse inside ()'s.
    ([ ($($tts:tt)*) $($tail:tt)*] [$($out:tt)*]) => {
        __WithLt!([$($tail)*] [
            $($out)* ( __WithLt!([$($tts)*] []) )
        ])
    };
    // Default case: do nothing.
    ([$tok:tt $($tail:tt)*] [$($out:tt)*]) => {
        __WithLt!([$($tail)*] [$($out)* $tok])
    };
    // Finished: output result.
    ([] [$($out:tt)*]) => { $($out)* };
}

// Should expand to:
// `type Test = for<'__lt> dyn WithLt<'__lt, Output=(&'__lt u32, &'__lt i32)>`
type Test = WithLt![(&'_ u32, &'_ i32)];
```
Produces the following error:
```rust
error: macro expansion ignores token `,` and any following
  --> src/lib.rs:35:29
   |
27 |         __WithLt!([$($tail)*] [$($out)* $tok])
   |         -------------------------------------- caused by the macro expansion here
...
35 | type Test = WithLt![(&'_ u32, &'_ i32)];
   |                             ^
   |
   = note: the usage of `__WithLt!` is likely invalid in type context

warning: unnecessary parentheses around type
  --> src/lib.rs:30:30
   |
30 |     ([] [$($out:tt)*]) => { $($out)* };
   |                              ^^^^^^
...
35 | type Test = WithLt![(&'_ u32, &'_ i32)];
   |             --------------------------- in this macro invocation
   |
   = note: `#[warn(unused_parens)]` on by default
   = note: this warning originates in the macro `__WithLt` which comes from the expansion of the macro `WithLt` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Dumping the expanded code with `cargo expand` gives:
```rust
type Test = dyn for<'__lt> WithLt<'__lt, Output = (&'__lt u32)>;
```
confirming that the macro stopped expanding at the first `,`.

However, using the unstable `trace_macros` feature, we see what seems to be a complete expansion:

<details><summary>Trace macro output</summary><p>

```rust
note: trace_macro
  --> src/main.rs:38:17
   |
38 |     type Test = WithLt![(&'_ u32, &'_ i32)];
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: expanding `WithLt! { (& '_ u32, & '_ i32) }`
   = note: to `dyn for < '__lt > WithLt < '__lt, Output = __WithLt!
           ([(& '_ u32, & '_ i32)] []) >`
   = note: expanding `__WithLt! { [(& '_ u32, & '_ i32)] [] }`
   = note: to `__WithLt! ([] [(__WithLt! ([& '_ u32, & '_ i32] []))])`
   = note: expanding `__WithLt! { [] [(__WithLt! ([& '_ u32, & '_ i32] []))] }`
   = note: to `(__WithLt! ([& '_ u32, & '_ i32] []))`
   = note: expanding `__WithLt! { [& '_ u32, & '_ i32] [] }`
   = note: to `__WithLt! (['_ u32, & '_ i32] [&])`
   = note: expanding `__WithLt! { ['_ u32, & '_ i32] [&] }`
   = note: to `__WithLt! ([u32, & '_ i32] [& '__lt])`
   = note: expanding `__WithLt! { [u32, & '_ i32] [& '__lt] }`
   = note: to `__WithLt! ([, & '_ i32] [& '__lt u32])`
   = note: expanding `__WithLt! { [, & '_ i32] [& '__lt u32] }`
   = note: to `__WithLt! ([& '_ i32] [& '__lt u32,])`
   = note: expanding `__WithLt! { [& '_ i32] [& '__lt u32,] }`
   = note: to `__WithLt! (['_ i32] [& '__lt u32, &])`
   = note: expanding `__WithLt! { ['_ i32] [& '__lt u32, &] }`
   = note: to `__WithLt! ([i32] [& '__lt u32, & '__lt])`
   = note: expanding `__WithLt! { [i32] [& '__lt u32, & '__lt] }`
   = note: to `__WithLt! ([] [& '__lt u32, & '__lt i32])`
   = note: expanding `__WithLt! { [] [& '__lt u32, & '__lt i32] }`
   = note: to `& '__lt u32, & '__lt i32`
```

</p></details>