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 edition 2024 match ergonomics restrictions #131381

Merged
merged 7 commits into from
Oct 16, 2024

Conversation

Nadrieril
Copy link
Member

@Nadrieril Nadrieril commented Oct 7, 2024

This implements the minimalest version of match ergonomics for edition 2024. This minimal version makes it an error to ever reset the default binding mode. The implemented proposal is described precisely here, where it is called "RFC 3627-nano".

Rules:

  • Rule 1C: When the DBM (default binding mode) is not move (whether or not behind a reference), writing mut, ref, or ref mut on a binding is an error.
  • Rule 2C: Reference patterns can only match against references in the scrutinee when the DBM is move.

This minimal version is forward-compatible with the main proposals for match ergonomics 2024: RFC3627 itself, the alternative rule 4-early variant, and others. The idea is to give us more time to iron out a final proposal.

This includes a migration lint that desugars any offending pattern into one that doesn't make use of match ergonomics. Such patterns have identical meaning across editions.

This PR insta-stabilizes the proposed behavior onto edition 2024.

r? @ghost

Tracking:

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 7, 2024
@Nadrieril Nadrieril changed the title WIP: Implement edition 2024 match ergonomics changes WIP: Implement edition 2024 match ergonomics restrictions Oct 7, 2024
@Nadrieril Nadrieril marked this pull request as ready for review October 8, 2024 06:24
@Nadrieril
Copy link
Member Author

r? compiler

@Nadrieril Nadrieril added I-lang-nominated Nominated for discussion during a lang team meeting. A-patterns Relating to patterns and pattern matching A-edition-2024 Area: The 2024 edition labels Oct 8, 2024
@Nadrieril Nadrieril changed the title WIP: Implement edition 2024 match ergonomics restrictions Implement edition 2024 match ergonomics restrictions Oct 8, 2024
@traviscross traviscross added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 8, 2024
@traviscross
Copy link
Contributor

Thanks @Nadrieril. Lang discussed the RFC 3627-nano rules in our 2024-10-02 planning meeting, and people were on board with this. So let's...

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Oct 8, 2024

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

No concerns currently listed.

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!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
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 Oct 8, 2024
@traviscross traviscross added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 8, 2024
@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

1 similar comment
@tmandry
Copy link
Member

tmandry commented Oct 9, 2024

@rfcbot reviewed

@pnkfelix
Copy link
Member

pnkfelix commented Oct 9, 2024

@rfcbot reviewed

@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 Oct 9, 2024
@rfcbot
Copy link

rfcbot commented Oct 9, 2024

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

@traviscross traviscross removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 16, 2024
LL | let Foo(mut x) = &Foo(0);
| -^^^^^^^^^
| |
| help: desugar the match ergonomics: `&`
Copy link
Member

Choose a reason for hiding this comment

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

I think this message may be a little bit too obtuse for the average reader.

In particular, my guess is that the average person leveraging match ergnonomics may not even know that they are doing so, and so they will not necessarily understand what this help message is telling them to do.

I recommend rephrasing it with a little more direction. Perhaps: "add a & to the pattern you have written to correspond to the type of the expression being matched" ?

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 yeah excellent point

@pnkfelix
Copy link
Member

I had a nit regarding the diagnostic messaging here, but I don't think that needs to block landing this PR.

@pnkfelix pnkfelix closed this Oct 16, 2024
@pnkfelix pnkfelix reopened this Oct 16, 2024
@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 16, 2024

📌 Commit 2ef0a8f has been approved by pnkfelix

It is now in the queue for this repository.

@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 Oct 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 16, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#130822 (Add `from_ref` and `from_mut` constructors to `core::ptr::NonNull`.)
 - rust-lang#131381 (Implement edition 2024 match ergonomics restrictions)
 - rust-lang#131594 (rustdoc: Rename "object safe" to "dyn compatible")
 - rust-lang#131686 (Add fast-path when computing the default visibility)
 - rust-lang#131699 (Try to improve error messages involving aliases in the solver)
 - rust-lang#131757 (Ignore lint-non-snake-case-crate#proc_macro_ on targets without unwind)
 - rust-lang#131783 (Fix explicit_iter_loop in rustc_serialize)
 - rust-lang#131788 (Fix mismatched quotation mark)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c1ed1f1 into rust-lang:master Oct 16, 2024
12 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 16, 2024
Rollup merge of rust-lang#131381 - Nadrieril:min-match-ergonomics, r=pnkfelix

Implement edition 2024 match ergonomics restrictions

This implements the minimalest version of [match ergonomics for edition 2024](https://rust-lang.github.io/rfcs/3627-match-ergonomics-2024.html). This minimal version makes it an error to ever reset the default binding mode. The implemented proposal is described precisely [here](https://hackmd.io/zUqs2ISNQ0Wrnxsa9nhD0Q#RFC-3627-nano), where it is called "RFC 3627-nano".

Rules:
- Rule 1C: When the DBM (default binding mode) is not `move` (whether or not behind a reference), writing `mut`, `ref`, or `ref mut` on a binding is an error.
- Rule 2C: Reference patterns can only match against references in the scrutinee when the DBM is `move`.

This minimal version is forward-compatible with the main proposals for match ergonomics 2024: [RFC3627](https://rust-lang.github.io/rfcs/3627-match-ergonomics-2024.html) itself, the alternative [rule 4-early variant](https://rust-lang.github.io/rfcs/3627-match-ergonomics-2024.html), and [others](https://hackmd.io/zUqs2ISNQ0Wrnxsa9nhD0Q). The idea is to give us more time to iron out a final proposal.

This includes a migration lint that desugars any offending pattern into one that doesn't make use of match ergonomics. Such patterns have identical meaning across editions.

This PR insta-stabilizes the proposed behavior onto edition 2024.

r? `@ghost`

Tracking:

- rust-lang#123076
@Nadrieril Nadrieril deleted the min-match-ergonomics branch October 17, 2024 07:02
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. 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 Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2024 Area: The 2024 edition A-patterns Relating to patterns and pattern matching 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. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants