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

Implement ? macro repetition #47752

Merged
merged 18 commits into from
Feb 11, 2018
Merged

Implement ? macro repetition #47752

merged 18 commits into from
Feb 11, 2018

Conversation

mark-i-m
Copy link
Member

See rust-lang/rfcs#2298 (with disposition merge)

@rust-highfive
Copy link
Collaborator

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.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 25, 2018
@kennytm
Copy link
Member

kennytm commented Jan 25, 2018

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 😂

@mark-i-m
Copy link
Member Author

@kennytm I 100% agree. Thanks :)

@kennytm
Copy link
Member

kennytm commented Jan 26, 2018

@mark-i-m Please put the new ? syntax behind a feature gate since this is an unstable feature. You may refer to :vis (search for macro_vis_matcher) to know how this works.

@bors
Copy link
Contributor

bors commented Jan 26, 2018

☔ The latest upstream changes (presumably #47748) made this pull request unmergeable. Please resolve the merge conflicts.

@mark-i-m
Copy link
Member Author

@kennytm Done.

@mark-i-m
Copy link
Member Author

This doesn't have a tracking issue yet, so when that happens, I should update the feature gate...

@mark-i-m
Copy link
Member Author

Also the unstable book...

Copy link
Contributor

@nikomatsakis nikomatsakis left a 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)) => {
Copy link
Contributor

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.

Copy link
Contributor

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)?+) => {}
}
Copy link
Contributor

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)?+) => {}
}
Copy link
Contributor

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.

Copy link
Contributor

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)?) => {}
Copy link
Contributor

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

@@ -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 `?`
Copy link
Contributor

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)

Copy link
Member Author

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?

Copy link
Contributor

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 `?`
Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is wrong =)

@mark-i-m
Copy link
Member Author

@nikomatsakis

wait-- so $(a),? is accepted but the , is just a no-op? seems like it should be an error

How would you feel about a lint instead? I would like to keep the separator simply for consistency with + and * even though having a separator on "at most once" is silly.

@mark-i-m
Copy link
Member Author

@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...

@mark-i-m mark-i-m changed the title [WIP] Implement ? macro repetition Implement ? macro repetition Jan 29, 2018
@bors
Copy link
Contributor

bors commented Jan 30, 2018

☔ The latest upstream changes (presumably #47870) made this pull request unmergeable. Please resolve the merge conflicts.

@mark-i-m
Copy link
Member Author

until #47732, #47603 are merged

They have merged now 🎉 ... I will rebase shortly

@nikomatsakis
Copy link
Contributor

How would you feel about a lint instead? I would like to keep the separator simply for consistency with + and * even though having a separator on "at most once" is silly.

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.

@mark-i-m
Copy link
Member Author

mark-i-m commented Feb 9, 2018

Updated

@CAD97
Copy link
Contributor

CAD97 commented Feb 9, 2018

Failure is due to added (see tracking issue):

[00:53:32] ---- [ui] ui/feature-gate-macro_at_most_once_rep.rs stdout ----
[00:53:32] 	diff of stderr:
[00:53:32] 
[00:53:32] -	error[E0658]: Using the `?` macro Kleene operator for "at most one" repetition is unstable
[00:53:32] +	error[E0658]: Using the `?` macro Kleene operator for "at most one" repetition is unstable (see issue #48075)

@mark-i-m
Copy link
Member Author

mark-i-m commented Feb 9, 2018

Thanks! Fixed.

@mark-i-m
Copy link
Member Author

mark-i-m commented Feb 9, 2018

hmm... tidy is now complaining that that line is too long 🤕

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 9, 2018

📌 Commit b92e542 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 9, 2018
@bors
Copy link
Contributor

bors commented Feb 11, 2018

⌛ Testing commit b92e542 with merge e8b05f5bd4c89faa3f2b4718e6582acd05da08be...

@bors
Copy link
Contributor

bors commented Feb 11, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 11, 2018
@kennytm
Copy link
Member

kennytm commented Feb 11, 2018

@bors retry #48116

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2018
@bors
Copy link
Contributor

bors commented Feb 11, 2018

⌛ Testing commit b92e542 with merge b8398d9...

bors added a commit that referenced this pull request Feb 11, 2018
Implement `?` macro repetition

See rust-lang/rfcs#2298 (with disposition merge)
@bors
Copy link
Contributor

bors commented Feb 11, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing b8398d9 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants