-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 |
after pat
in macro_rules!
#20824
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (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. 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 CONTRIBUTING.md for more information. |
Could you add a test for this as well? I'd like a second opinion on this, but I believe this to be valid as I don't believe it's possible for us to ever expand the pattern grammar to include a trailing |
I want to ensure that we'll be able to expand the pattern syntax to allow stuff like |
@sfackler |
Ah right. Maybe we want to make the check a bit smarter and add separate FOLLOW and BETWEEN sets? |
To clarify: my motivation is to write a macro that accepts whatever comes before I don’t care how this is achieved or if I have to change the implementation (e.g. if a single |
I’m not convinced this is the right fix, but I’m counting on Cunningham’s Law. |
Added a test, but
|
Our pretty printer isn't necessarily always the best (especially with macros), so feel free to add |
How exactly is Also, if this PR went through and macro_rules! foo {
($($p: pat)|+) => {{
$(let $p = 1i32;)+
}}
}
foo!(x | y); I disagree that this change should go through primarily because it's (in my opinion) the wrong solution to a relatively minor aesthetic problem. The right solution (to me) is to extend |
That sound great! Can I haz it?
Or, not. |
Per rust-lang#20563 (comment) This enables writing macros that accept `$($pattern:pat)|+` and expand to the same thing in a `match` statement. See for example [the `matches!` macro](https://github.com/SimonSapin/rust-std-candidates#the-matches-macro).
0b54f1c
to
da9e0be
Compare
Closing since this is probably not the right fix, and there is a workaround. I opened #20843 for the original issue. |
Per #20563 (comment)
This enables writing macros that accept
$($pattern:pat)|+
and expand to the same thing in amatch
statement. See for example thematches!
macro.r? @alexcrichton