Repository: rust
Issue: Diagnostic improvement of macros
Labels: A-diagnostics,T-compiler

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.

If you cannot produce a minimal reproduction case (something that would work in
isolation), please provide the steps or even link to a repository that causes
the problematic output to occur.
-->

Given the following code: <!-- Please provide a link to play.rust-lang.org -->

```rust
macro_rules! m {
    () => {};
    ( $name:ident; ($tt:tt)* ) => {
        m!{ @ $name }
        m!{ $($tt)* }
    };
    (@ $name:ident) => { struct $name; };
}

m! {
    A;
    B;
}

m! { C; }
```

[Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=2a4b2c1192d04f81a973bc5a72ed9994).

The current output is:

```
error: no rules expected the token `B`
  --> src/lib.rs:12:5
   |
1  | macro_rules! m {
   | -------------- when calling this macro
...
12 |     B;
   |     ^ no rules expected this token in macro call

error: unexpected end of macro invocation
  --> src/lib.rs:15:8
   |
1  | macro_rules! m {
   | -------------- when calling this macro
...
15 | m! { C; }
   |        ^ missing tokens in macro arguments

error: could not compile `playground` due to 2 previous errors
```

<!-- The following is not always necessary. -->
Ideally the output should look like:

```
error: no rules expected the token `B`
  --> src/lib.rs:12:5
   |
1  | macro_rules! m {
   | -------------- when calling this macro
...
12 |     B;
   |     ^ no rules expected this token in macro call

note: expected `(` but found `B`.
  --> src/lib.rs:3:20
   |
3  |    ( $name:ident; ($tt:tt)* ) => {
   |                   ^ expected token `(`.
...
12 |     B;
   |     ^ But found `B`.
help: do you mean this?
  --> src/lib.rs:3:20
   |
3  |    ( $name:ident; ($tt:tt)* ) => {
   +                   $($tt:tt)* ) => {
   |                   ^ Add `$` here.


error: unexpected end of macro invocation
  --> src/lib.rs:15:8
   |
1  | macro_rules! m {
   | -------------- when calling this macro
...
15 | m! { C; }
   |        ^ missing tokens in macro arguments

note: missing `(` but found nothing.
  --> src/lib.rs:3:20
   |
3  |    ( $name:ident; ($tt:tt)* ) => {
   |                   ^ expected token `(`.
...
15 | m! { C; }
   |        ^ missing tokens in macro arguments

help: do you mean this?
  --> src/lib.rs:3:20
   |
3  |    ( $name:ident; ($tt:tt)* ) => {
   +                   $($tt:tt)* ) => {
   |                   ^ Add `$` here.
error: could not compile `playground` due to 2 previous errors
```

The expect error message is written by hand.

The original problem comes from [here](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a52ef2edc10fc0ba8f841090ce6adaa6). It has wasted me a couple of hours to find out the error (a missing `$` in the macro rules), so I hope the diagnostic message can be improved, to avoid another one being stuck by this.

If the compiler can not report that I missed a `$`, I hope at least it can report that the next expected token `(` doesn't match the actual arguments.

<!--
If the problem is not self-explanatory, please provide a rationale for the
change.
-->

<!--
If dramatically different output is caused by small changes, consider also
adding them here.

If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions. The output might also be
different depending on the Edition.
-->