-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement ?
macro repetition
#47752
Implement ?
macro repetition
#47752
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (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. |
Marking as blocked by #47732, #47603, and of course rust-lang/rfcs#2298. I don't think this can be easily reviewed with all those formatting change 😂 |
@kennytm I 100% agree. Thanks :) |
@mark-i-m Please put the new |
☔ The latest upstream changes (presumably #47748) made this pull request unmergeable. Please resolve the merge conflicts. |
4652013
to
abfdbdf
Compare
@kennytm Done. |
This doesn't have a tracking issue yet, so when that happens, I should update the feature gate... |
Also the unstable book... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start, nice work! Left various comments, will re-review once addressed.
// #1 is `?` token, but it could be a Kleene::ZeroOrOne without a separator or it could | ||
// be a `?` separator followed by any Kleene operator. We need to look ahead 1 token to | ||
// find out which. | ||
Ok(Ok(op)) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can we add assert_eq!(op, KleeneOp::ZeroOrOne);
here? I find it helps catch mistakes when later somebody messes with the arms accidentally....
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always appreciate a comment here explaining what this test is trying to do. Example:
Test that in $(a)?+
, the ?
is interpreted as a separator, but not for $(a)?
. This test focuses on error cases.
|
||
macro_rules! bar { | ||
($(a)?+) => {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about $(a)?*
? we should test that too, no?
|
||
macro_rules! bar { | ||
($(a)?+) => {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about $(a)?*
? we should test that too, no?
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment =)
// except according to those terms. | ||
|
||
macro_rules! foo { | ||
($(a)?) => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these tests would be better if they had things in the body that made use of a
src/test/compile-fail/issue-39388.rs
Outdated
@@ -11,7 +11,7 @@ | |||
#![allow(unused_macros)] | |||
|
|||
macro_rules! assign { | |||
(($($a:tt)*) = ($($b:tt))*) => { //~ ERROR expected `*` or `+` | |||
(($($a:tt)*) = ($($b:tt))*) => { //~ ERROR 14:22: 14:29: expected one of: `*`, `+`, or `?` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to a ui
test instead of hard-coding spans and things (i.e., the 14:22
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I intended to remove the line/col numbers but forgot... Should I still move to a ui
test if I remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter so much. I believe ui
tests are generally "the future" but this test can stay a compile-fail test.
@@ -12,13 +12,19 @@ macro_rules! foo { | |||
($(a)?) => {} | |||
} | |||
|
|||
macro_rules! baz { | |||
($(a),?) => {} // comma separator is meaningless for `?` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait-- so $(a),?
is accepted but the ,
is just a no-op? seems like it should be an error
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that the MSP430 interrupt ABI cannot be used when msp430_interrupt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is wrong =)
How would you feel about a lint instead? I would like to keep the separator simply for consistency with |
@nikomatsakis I think I addressed your comments. You may want to wait on a re-review until #47732, #47603 are merged, as they will make the diffs easier to read... |
?
macro repetition?
macro repetition
☔ The latest upstream changes (presumably #47870) made this pull request unmergeable. Please resolve the merge conflicts. |
Maybe we should bring this up in the RFC thread and get others' opinions. I don't have a very strong opinion, but it seems like an error would be better to me. |
Updated |
Failure is due to added
|
Thanks! Fixed. |
hmm... tidy is now complaining that that line is too long 🤕 |
@bors r+ |
📌 Commit b92e542 has been approved by |
⌛ Testing commit b92e542 with merge e8b05f5bd4c89faa3f2b4718e6582acd05da08be... |
💔 Test failed - status-appveyor |
Implement `?` macro repetition See rust-lang/rfcs#2298 (with disposition merge)
☀️ Test successful - status-appveyor, status-travis |
See rust-lang/rfcs#2298 (with disposition merge)