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

Comments

Projects
None yet
5 participants
@Stebalien
Copy link
Contributor

Stebalien commented Jul 2, 2015

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

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jul 9, 2015

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!

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jan 14, 2016

This was fixed by #30694

@pnkfelix pnkfelix closed this Jan 14, 2016

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Jan 14, 2016

(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
You can’t perform that action at this time.