Skip to content

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

Closed
ghost wants to merge 2 commits into
masterfrom
unknown repository
Closed

Add support for counting syntactic matches in a macro definition#12916
ghost wants to merge 2 commits into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Mar 15, 2014

Copy link
Copy Markdown

This is a proposed solution for #12782.

@huonw

huonw commented Mar 16, 2014

Copy link
Copy Markdown
Contributor

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

ghost commented Mar 16, 2014

Copy link
Copy Markdown
Author

@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

ghost commented Mar 24, 2014

Copy link
Copy Markdown
Author

@huonw Any thoughts on this one?

@huonw

huonw commented Mar 24, 2014

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

cc @paulstansifer

@alexcrichton

Copy link
Copy Markdown
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.

4 participants