Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In macros, expr followed by { is buggy #26739

Closed
Stebalien opened this issue Jul 2, 2015 · 3 comments
Closed

In macros, expr followed by { is buggy #26739

Stebalien opened this issue Jul 2, 2015 · 3 comments
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) P-high High priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Stebalien
Copy link
Contributor

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 { }
                          ^
@Stebalien Stebalien changed the title In macros, rust allows expr to be followed by { In macros, expr followed by { is buggy Jul 2, 2015
@huonw huonw added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Jul 2, 2015
@nikomatsakis
Copy link
Contributor

triage: P-high (decision needed)

For this and other macro rules, it's unclear how much we can change here, but I think we should make an effort to fix these bugs sooner rather than later if we are going to do so!

@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Jul 9, 2015
@pnkfelix
Copy link
Member

This was fixed by #30694

@pnkfelix
Copy link
Member

(though i will note yet again that there may be motivation for adding a new syntactic class to macro rules, which I have been referring to tongue-in-cheek as $e:moelarry, but obviously we'd want to bikeshed a better name before we'd actually put it in for real...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) P-high High priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants