Skip to content

Clarify that expr/stmt in macros can may only be followed by one of: => , ; #34069

Closed
@dashed

Description

@dashed

For the code:

macro_rules! foo {
    ($something:expr invalid) => {{
        // ...
    }};
}

macro_rules! bar {
    ($something:stmt invalid) => {{
        // ...
    }};
}

fn main() {
    foo!(true invalid);
    bar!(true invalid);
}

https://is.gd/TFIoq1

The compiler would give the following errors for this

error: `$something:expr` is followed by `invalid`, which is not allowed for `expr` fragments
 --> <anon>:2:22
2 |>     ($something:expr invalid) => {{
  |>                      ^^^^^^^

error: `$something:stmt` is followed by `invalid`, which is not allowed for `stmt` fragments
 --> <anon>:8:22
8 |>     ($something:stmt invalid) => {{
  |>    

I think it would be better if the error clarified that expr/stmt in macros can may only be followed by one of: => , ;

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions