Skip to content

In macros, expr followed by { is buggy #26739

Closed
@Stebalien

Description

@Stebalien

The following compiles:

macro_rules! test {
    ($e:expr {}) => {$e};
}

However, (1) this technically isn't allowed by the macro future proofing rules and (2) it doesn't work when $e is an ident because rust tries to parse ident {} as an invalid struct literal instantiation.

The following works:

test! {
    1 + 1 { } // 1 + 1 can be anything other than an ident.
};

And the following doesn't:

test! {
        ident { }
};

Error:

tmp.rs:10:15: 10:16 error: structure literal must either have at least one field or use functional structure update syntax
tmp.rs:10         ident { }
                        ^
tmp.rs:10:17: 10:18 error: unexpected end of macro invocation
tmp.rs:10         ident { }
                          ^

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)P-highHigh priorityT-langRelevant to the language 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