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

Allow [] for macro invocation in item places #35833

Closed
wants to merge 1 commit into from

Conversation

bossmc
Copy link
Contributor

@bossmc bossmc commented Aug 19, 2016

The following code doesn't compile:

macro_rules! unit {
    ($name:ident) => { struct $name; }
}

unit!(Parens);
unit!{Braces}
unit![Brackets];

With the following compliant:

src/test/run-pass/macro-delimiters-in-item-position.rs:17:1: 17:5 error: expected item, found `unit`
src/test/run-pass/macro-delimiters-in-item-position.rs:17 unit![Brackets];
                                                          ^~~~
error: aborting due to previous error

It seems that, unlike in expr position, item macros couldn't be invoked with name![...]. This seems to be caused by a copy-paste issue, where the "could this be a macro" test is repeated in various places but with slightly different logic in each.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@pnkfelix
Copy link
Member

cc @rust-lang/lang especially @nrc ; are we okay with this generalization to macro syntax?

@pnkfelix pnkfelix added I-nominated I-needs-decision Issue: In need of a decision. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Sep 23, 2016
@nrc
Copy link
Member

nrc commented Sep 25, 2016

We should not do this. Macro use syntax follows from the regular syntax allowed in that context - so macros in statement position need a ; and those in expression position do not, etc. For item position, we have items which are braced and those with (...);, we do not have any items that have square brackets, so we should not allow macros with square brackets either.

@bossmc
Copy link
Contributor Author

bossmc commented Sep 26, 2016

Interesting, I wasn't aware of that symmetry between macros and their resolved forms.

I'm happy either way, but as a counter-point argument for allowing [], I often chose to use macro![...] to make it easier to see where a scope is a macro body as opposed to another (parenthetical) scope.

Feel free to close this PR if you want to stick with the restricted syntax.

@bors
Copy link
Contributor

bors commented Sep 27, 2016

☔ The latest upstream changes (presumably #36764) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

I agree that the intention was basically to mirror existing forms (e.g., tuple structs) and that extending to [] seems to defeat that intention.

@pnkfelix
Copy link
Member

pnkfelix commented Oct 6, 2016

@rfcbot fcp close

@pnkfelix
Copy link
Member

pnkfelix commented Oct 6, 2016

oh ha ha this is the rust repo, so rfcbot is irrelevant


(or maybe something will happen ... in .... time ....)

@pnkfelix
Copy link
Member

pnkfelix commented Oct 6, 2016

This seems like a sufficiently significant change that it would require an RFC.

(you are welcome to compose such an RFC, but the lang team currently does not seem terribly disposed to the idea, so you should probably first see about building up a solid argument for it, perhaps via community discussion either on the IRC channels or in the internals.rust-lang.org forum.)

@pnkfelix pnkfelix closed this Oct 6, 2016
@rfcbot
Copy link

rfcbot commented Oct 6, 2016

FCP proposed with disposition to close. Review requested from:

No concerns currently listed.
See this document for info about what commands tagged team members can give me.

@nikomatsakis
Copy link
Contributor

@rfcbot fcp cancel

@rfcbot
Copy link

rfcbot commented Oct 7, 2016

@nikomatsakis FCP proposal cancelled.

@bossmc bossmc deleted the allow-brackets-around-macros branch October 7, 2016 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-needs-decision Issue: In need of a decision. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants