Skip to content

Regression in error message quality for macro_rules involving $:ident #69604

Open
@dtolnay

Description

@dtolnay

Between nightly-2020-02-28 and nightly-2020-02-29 I observed that macro errors which used to point to a specific problematic identifier token now point equivocally to the entire macro invocation. See dtolnay/tt-call@364468e.

The issue minimizes to:

macro_rules! nothing_expected {
    () => {};
}

macro_rules! repro {
    ($ident:ident) => {
        nothing_expected!($ident);
    };
}

repro!(T);

Before; points to T:

error: no rules expected the token `T`
  --> src/main.rs:11:8
   |
1  | macro_rules! nothing_expected {
   | ----------------------------- when calling this macro
...
11 | repro!(T);
   |        ^ no rules expected this token in macro call

After; does not point to T:

error: no rules expected the token `T`
  --> src/main.rs:7:27
   |
1  | macro_rules! nothing_expected {
   | ----------------------------- when calling this macro
...
7  |         nothing_expected!($ident);
   |                           ^^^^^^ no rules expected this token in macro call
...
11 | repro!(T);
   | ---------- in this macro invocation
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

The applicable commit range is 6d69cab...0eb878d.
The most relevant looking PR in that range is #69384. @petrochenkov @Centril

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.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions