Skip to content

Parser mistakes macro argument for struct initialization? #15198

Closed
@hannobraun

Description

@hannobraun

When I updated to Rust master yesterday, some of my macro invocations broke in an interesting way. Here's a reduced example:

#![feature(macro_rules)]

macro_rules! my_macro(
    ($condition:expr $action:block) => ({})
)

fn main() {
    my_macro!(0 == y {
        y = 1;
    });
}
$ rustc main.rs
main.rs:10:5: 10:6 error: expected `:` but found `=`
main.rs:10      y = 1;
                  ^

With this workaround, it compiles without errors:

#![feature(macro_rules)]

macro_rules! my_macro(
    ($condition:expr $action:block) => ({})
)

fn main() {
    my_macro!(0 == y && true {
        y = 1;
    });
}

Looks to me like the parser sees "y { ..." and mistakes it for a struct initialization.

This problem occurs with commit 2f74325.
Before the upgrade, it worked fine with commit db29814.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions