Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhelpful error message in macros which invoke other macros #35150

Closed
tiffany352 opened this issue Jul 31, 2016 · 2 comments
Closed

Unhelpful error message in macros which invoke other macros #35150

tiffany352 opened this issue Jul 31, 2016 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@tiffany352
Copy link

The problematic code:

macro_rules! x {
    ($a:expr, $b:expr) => {}
}

macro_rules! y {
    ($a:expr, $b:expr) => {
        x!($a, $b)
    }
}

// much later

fn foo() {
    macro_rules! x {
        ($a:expr) => {}
    }

    // later still

    y!(1, 2)
}

Rustc output:

error: no rules expected the token `,`
 --> <anon>:8:14
8 |>         x!($a, $b)
  |>              ^

Playpen link

This error points out that the y! macro performed an incorrect invocation of the x! macro, but fails to point out which x! macro in particular it is trying to invoke, or the location where the y! macro was invoked. In addition, it doesn't point out tokens which the macro would accept (in this case, the end of the invocation).

@eddyb eddyb added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Jul 31, 2016
@eddyb
Copy link
Member

eddyb commented Aug 1, 2016

cc @jonathandturner

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 25, 2017
@estebank
Copy link
Contributor

estebank commented Aug 8, 2018

Current output still doesn't point at the called macro's definition (like we do for functions):

error: no rules expected the token `,`
  --> src/main.rs:8:14
   |
8  |         x!($a, $b)
   |              ^
...
21 |     y!(1, 2)
   |     -------- in this macro invocation

kennytm added a commit to kennytm/rust that referenced this issue Oct 26, 2018
Point at macro definition when no rules expect token

Fix rust-lang#35150.
kennytm added a commit to kennytm/rust that referenced this issue Oct 26, 2018
Point at macro definition when no rules expect token

Fix rust-lang#35150.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants