Skip to content

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

Closed
@oli-obk

Description

@oli-obk

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

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

    No branches or pull requests

    Issue actions