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

Allow leading pipe in matches!() patterns. #85272

Merged
merged 1 commit into from
Aug 2, 2021

Conversation

ChayimFriedman2
Copy link
Contributor

This is allowed in match statement, and stated in https://internals.rust-lang.org/t/leading-pipe-in-core-matches/14699/2 that it should be allowed in these macros too.

@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 13, 2021
@m-ou-se m-ou-se added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 17, 2021
@m-ou-se
Copy link
Member

m-ou-se commented May 17, 2021

@rfcbot merge

@rfcbot
Copy link

rfcbot commented May 17, 2021

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels May 17, 2021
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Is it possible to add tests for this?

@ChayimFriedman2
Copy link
Contributor Author

There weren't tests for the matches!() macro previously, so I thought it is not needed. But I can do.

@m-ou-se m-ou-se added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 19, 2021
@yaahc
Copy link
Member

yaahc commented May 21, 2021

I want to second @BurntSushi's request for tests.

@rfcbot concern add tests

@ChayimFriedman2
Copy link
Contributor Author

Done. Thanks.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 26, 2021

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

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 26, 2021
@rust-log-analyzer

This comment has been minimized.

@ChayimFriedman2
Copy link
Contributor Author

Seems like rustfmt strongly prefers matches!(1, |1| 2 | 3) over matches!(1, | 1 | 2 | 3). What should I do?

@joshtriplett
Copy link
Member

File a bug on rustfmt, and add #[rustfmt::skip] on the function along with a comment linking to the bug.

@ChayimFriedman2
Copy link
Contributor Author

I'm not sure this is a bug. It does not come when the macro delimiters are braces (m! { ... }), and the reason is probably that rustfmt sees | 1 | 2 | 3 as |1| (2 | 3), that is, a closure that destructures its argument to 1 and returns 2 | 3, or 3.

@joshtriplett
Copy link
Member

@ChayimFriedman2 It's entirely understandable why it's happening. It's just an issue once matches! accepts leading |.

@JohnCSimon
Copy link
Member

Ping from triage:
@ChayimFriedman2 can you post your status on this PR?
Is this blocked waiting on rustfmt? if so please add the s-blocked tag

@calebcartwright
Copy link
Member

I'm not sure this is a bug. It does not come when the macro delimiters are braces (m! { ... }), and the reason is probably that rustfmt sees | 1 | 2 | 3 as |1| (2 | 3), that is, a closure that destructures its argument to 1 and returns 2 | 3, or 3.

Two general things happening here:

  • rustfmt behaves differently on maccalls depending on the delim. It'll basically do nothing with braces, and with parens and brackets will try to see if it looks like normal rust code and attempt to format accordingly. Using braces is often a viable escape hatch
  • We still don't do any special case handling for matches! like we do for a couple other macros. It's on the todo list but no clue when I'll get around to it.

As such the way rustfmt formats matches! today is already strange because the current second arg (sans leading pipe) can be parsed as a binop expr and gets formatted accordingly. The resultant formatting admittedly looks a bit worse with the addition of a leading pipe, but just another symptom of an existing gap as opposed to something net new.

@ChayimFriedman2
Copy link
Contributor Author

So #[rustfmt::skip]? Or perhaps format it like rustfmt wants?

@crlf0710
Copy link
Member

crlf0710 commented Jul 4, 2021

@ChayimFriedman2 Ping from triage, what's next steps here?

@ChayimFriedman2
Copy link
Contributor Author

What should I do to the tests? #[rustfmt::skip]? Fill an issue?

@ChayimFriedman2
Copy link
Contributor Author

Done.

@m-ou-se
Copy link
Member

m-ou-se commented Jul 6, 2021

@yaahc can you resolve your concern with rfcbot?

@yaahc
Copy link
Member

yaahc commented Jul 6, 2021

@rfcbot resolve add tests

@rfcbot
Copy link

rfcbot commented Jul 6, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jul 6, 2021
@bors
Copy link
Contributor

bors commented Jul 15, 2021

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

This is allowed in `match` statement, and stated in https://internals.rust-lang.org/t/leading-pipe-in-core-matches/14699/2 that it should be allowed in these macros too.
@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Jul 16, 2021
@rfcbot
Copy link

rfcbot commented Jul 16, 2021

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot added to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jul 16, 2021
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 31, 2021
@m-ou-se m-ou-se added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. labels Aug 1, 2021
@m-ou-se
Copy link
Member

m-ou-se commented Aug 1, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Aug 1, 2021

📌 Commit f10da9f has been approved by m-ou-se

@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 Aug 1, 2021
@bors
Copy link
Contributor

bors commented Aug 2, 2021

⌛ Testing commit f10da9f with merge 24bbf7a...

@bors
Copy link
Contributor

bors commented Aug 2, 2021

☀️ Test successful - checks-actions
Approved by: m-ou-se
Pushing 24bbf7a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 2, 2021
@bors bors merged commit 24bbf7a into rust-lang:master Aug 2, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 2, 2021
@ChayimFriedman2 ChayimFriedman2 deleted the matches-leading-pipe branch August 2, 2021 22:27
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.