-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
No way to have + or * as separator token in macros #18700
Comments
Triage: no change. Not sure this is going to be implemented with the current macro system. |
@nrc will macros 3.0 or whatever potentially enable this? |
It's not part of my plans, but it seems like something we could address separately (once the new system is in place I mean, not in the old system). |
Triage: no change |
There's a workaround for this, just use the following utility macro: macro_rules! strip_plus {
{+ $($rest:tt)* } => { $($rest)* }
} Then, in your main macro instead of writing |
There is a similar problem with separators in patterns: macro_rules! example {
( $( $i:ident )+* ) => {}
} This is allowed, however it works as 'at least one There is also a workaround: macro_rules! workaround {
( $( $first:ident $( + $rest:ident )* )? ) => {}
} But it makes the macro a lot less readable (and forces you to repeat the pattern twice). Are there any plans to do something with this issue? (maybe reopen rust-lang/rfcs#944 ?) |
fix: Fix a panic with a diagnostics fix when a keyword is used as a field
I'm trying to write a macro that sums a list of expressions, but it doesn't work because it's not possible to have + or * as the seperator token. For example:
It'll interpret is as there being no seperator token, and it seems to just stick a
+
at the end. Escaping the first+
doesn't work either.I'm using rust head
@bstrie
The text was updated successfully, but these errors were encountered: