Skip to content

Wrong span/confusing error for comma in macro pattern #60233

@oli-obk

Description

@oli-obk
Contributor

I don't know what to make of this error.

use std::fmt::Debug;

macro_rules! check {
    ($ty:ty, $expected:expr) => {
        
    };
    ($ty_of:expr, $expected:expr) => {
        
    };
}

fn main() {
    check!(
        <str as Debug>::fmt,
        "foo",
    );
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found `,`
  --> src/main.rs:14:16
   |
14 |         <str as Debug>::fmt,
   |                ^
   |                |
   |                expected identifier
   |                help: remove this comma

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

On stable (1.34) the output is

error: expected identifier, found `,`
  --> src/main.rs:14:25
   |
14 |         <str as Debug>::fmt,
   |                         ^
   |                         |
   |                         expected identifier
   |                         help: remove this comma

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
on Apr 24, 2019
added
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 24, 2019
estebank

estebank commented on Apr 24, 2019

@estebank
Contributor

I'm pretty sure this is fallout from the "missing comma here" suggestion for macros, that evaluates the macro again with the current arguments but adding a comma token in between the argument tokens in different combinations to see if it would be correct. My guess is that that is causing a parse error that doesn't happen for normal things than only have one token in them. We can disable the suggestion when fully qualified paths are involved.

added a commit that references this issue on Apr 25, 2019
112f7e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @oli-obk@estebank@jonas-schievink

      Issue actions

        Wrong span/confusing error for comma in macro pattern · Issue #60233 · rust-lang/rust