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

Always parse macro invocations with () or [] as expressions #378

Closed
wants to merge 2 commits into from

Conversation

ftxqxd
Copy link
Contributor

@ftxqxd ftxqxd commented Oct 9, 2014

Parse macro invocations with parentheses or square brackets as expressions no matter the context, and require curly braces or a semicolon following the invocation to invoke a macro as a statement.

Resolves #364.

I think #208 also does this as a by-product of resolving another ambiguity with attributes.


Status: Active
RFC document: https://github.com/rust-lang/rfcs/blob/master/text/0378-expr-macros.md

@pnkfelix
Copy link
Member

pnkfelix commented Oct 9, 2014

I can shepherd this. Assigning to self.

@pnkfelix pnkfelix self-assigned this Oct 9, 2014
@reem
Copy link

reem commented Oct 9, 2014

+1. I would like this change because it would make expression macros much more usable, especially those like the one in https://github.com/reem/rust-enforce.

@nrc
Copy link
Member

nrc commented Oct 12, 2014

+1 I hope the semicolon rule for macros as statements (as opposed to as items) falls out naturally from the syntax for expressions and statements.

@brson
Copy link
Contributor

brson commented Oct 28, 2014

Curious what @pcwalton and @nikomatsakis think. I don't have strong opinion but it seems to be more consistent with non-macro stmt/expr parsing.

ISTR that macro!().method_call() doesn't parse correctly. Presumably that would be fixed by this proposal? If so it would be nice to call it out explicitly in the RFC.

This RFC is not using the template format for Rust RFCs.

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Oct 29, 2014

@brson The macro!().method_call() problem (which this RFC resolves) is already mentioned in the RFC.

@nikomatsakis
Copy link
Contributor

I am generally in favor of this. As @P1start noted, we had similar rules as part of the (now withdrawn) #208 RFC. One thing to clarify: these same restrictions would apply in all contexts, right? That is, also at the top-level:

declare_item!() // <-- error, semi colon required

fn foo() {
    declare_item!();
}

If so, I am in favor because it improves the overall consistency of the language. @foo() as an item declaration without a semicolon always looks wrong to me, it feels like items/statements should end in {} or ;.

@ftxqxd
Copy link
Contributor Author

ftxqxd commented Nov 1, 2014

Yes, these rules apply to item-position macros, too. The RFC states that it will ‘require all item-position macros to be invoked with either curly braces, {}, or be followed by a semicolon (for consistency)’.

@nikomatsakis
Copy link
Contributor

@P1start sounds good to me, I missed that somehow.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 4, 2014

Accepted (squashed and merged as 4738e17 )

discussion, tracking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax extensions (and macros) that start a line want to be a whole statement
6 participants