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

Match Ergonomics 2024: update old-edition behavior of feature gates #136093

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Jan 26, 2025

This updates the behavior of the feature gates ref_pat_eat_one_layer_2024_structural and ref_pat_eat_one_layer_2024 in Editions 2021 and earlier to correspond to the left and right typing rules compared here, respectively. Compared to the stable_rust rules:

  • they both allow reference patterns to match a lone inherited ref,
  • they both allow & patterns to eat &mut reference types (and lone &mut inherited refs) as if they're shared,
  • they both allow &mut patterns to eat & reference types when there's a &mut inherited reference to also eat,
  • and the left ruleset has RFC 3627's Rule 3: after encountering a shared reference type in the scrutinee, the default binding mode will be treated as by-shared-ref when it would otherwise be by-mutable-ref.

I think there's already tests for all of those typing rules, so I've added revisions to use the existing tests with the new rulesets. Additionally, I've added a few tests to make sure we handle mixed-edition patterns appropriately, and I've added references to the unstable book.

Relevant tracking issue: #123076

r? @ghost

@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 Jan 26, 2025
@dianne dianne force-pushed the match-2024-for-edition-2021 branch 2 times, most recently from 737d409 to d37a4d4 Compare January 28, 2025 05:44
@dianne dianne force-pushed the match-2024-for-edition-2021 branch from d37a4d4 to 29626d0 Compare January 31, 2025 00:05
@dianne dianne marked this pull request as ready for review January 31, 2025 00:06
@dianne
Copy link
Contributor Author

dianne commented Jan 31, 2025

This should now be ready for review, I think!

r? @Nadrieril

My reasoning: the ruleset implemented by the same feature gate in
Edition 2024 always tries to eat the inherited reference first. For
consistency, it makes sense to me to say across all editions that users
should consider the inherited reference's mutability when wondering if a
`&mut` pattern will type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants