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

Add support for counting syntactic matches in a macro definition #12916

Closed
wants to merge 2 commits into from
Closed

Add support for counting syntactic matches in a macro definition #12916

wants to merge 2 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 15, 2014

This is a proposed solution for #12782.

@huonw
Copy link
Member

huonw commented Mar 16, 2014

It would be good to have some tests for invalid and other edge cases too, e.g. all the cases in:

macro_rules! test {
     ($($($e: expr),*);*, $x: ident) => {
         (#($e),
          #($($e)*), 
          #($($($e)*)*),
          #($($e $e)*),
          #($($x $e)*),
          #($x),
          #($x $x),
          #($e $x),
          #(1))
          // etc.
     }
}

None of those should crash the compiler, and, preferably, they would do something sensible.

@ghost
Copy link
Author

ghost commented Mar 16, 2014

@huonw Actually, I should have made it clear that with this change, only the occurrences of an individual variable can be counted, not a whole pattern. So most of your examples will not parse.

I did add one more test for nested sequences which, as it turns out, didn't work properly.

@ghost
Copy link
Author

ghost commented Mar 24, 2014

@huonw Any thoughts on this one?

@huonw
Copy link
Member

huonw commented Mar 24, 2014

Oh, sorry (there's no notifications for when a PR is updated, so feel free to comment when you do so).

So most of your examples will not parse

If they are meant to emit compiler errors, you should add some compile-fail tests (explanation) to make sure that the compiler is doing the correct thing.

@emberian
Copy link
Member

cc @paulstansifer

@alexcrichton
Copy link
Member

We decided in today's meeting that while amenable, we'd like to see an RFC for this change to garner some discussion around it. It's unclear how well this interacts with the rest of the macro system, and we feel that an RFC would help flesh it out some more.

You can read up on the rfc process over at https://github.com/rust-lang/rfcs with RFC #1.

Thanks again for this PR, I'd love to see this get implemented!

@ghost ghost deleted the macro-match-count branch June 5, 2014 16:41
lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 2, 2022
minor: Properly cfg the `max` field of Limit
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.

3 participants