Skip to content

Unhelpful error message in macros which invoke other macros #35150

Closed
@tiffany352

Description

@tiffany352

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions