-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Draft
dianne
wants to merge
18
commits into
rust-lang:master
Choose a base branch
from
dianne:match-2024-for-edition-2021
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,481
−510
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The debug assertion ensuring that the pattern mutability cap holds assumes the presence of Rule 3, so it now checks for that. I considered going back to only tracking the mutability cap when Rule 3 is present, but since the mutability cap is used in Rule 5's implementation too, the debug assertion would still need to check which typing rules are present. This also required some changes to tests: - `ref_pat_eat_one_layer_2021.rs` had a test for Rule 3; I'll be handling tests for earlier editions in a later commit, so as a stopgap I've #[cfg]ed it out. - One test case had to be moved from `well-typed-edition-2024.rs` to `borrowck-errors.rs` in order to get borrowck to run on it and emit an error.
These come directly from the "Compare" tab of Typing Rust Patterns, though they had to be split across multiple files. They're not comprehensive, but they do provide some previously-missing coverage and are easier to check against the spec. Possibly they should be split up some more, since `pattern-errors.rs` is getting a bit unwieldy, but I'm not sure how best to go about that.
…back for inherited ref mutability mismatches I think the diagnostic could use some work, but it's more helpful than the alternative. The previous error was misleading, since it ignored the inherited reference altogether.
…e pattern doesn't match the mutability of an inner reference This is the `Deref(EatInner, FallbackToOuter)` rule in Typing Rust Patterns.
- Removes some excess parens - Removes 3 duplicated tests
This serves two purposes. First, they're additional tests that stable Rust behavior hasn't been messed with. There's plenty of other pattern tests, so this is less important, but these at least are targeted at what's being changed. Second, this helps document exactly where the new rulesets agree and disagree with stable pattern typing. This will be especially important after the new rules for old editions are updated, since they need to be strictly more permissive; any patterns well-typed on stable should also be well-typed with the same resultant bindings on the (upcoming) new new old-edition rules. The unusual test ordering on `borrowck-errors.rs` and `ref-binding-on-inh-ref-errors.rs` are to hopefully reduce how much adding new tests will mess with line numbers in their stderr.
This doesn't (or at least shouldn't!) add, remove, or change any test cases. I've grouped them by which rule variants they test.
…rules) Since there are so many ways to write these, I've opted to only include two sorts of test: simple tests that directly target the rules differing between rulesets and nuanced tests that produce different errors under different rulesets. I've also tried not to add any duplicate tests. `well-typed-edition-2024.rs` already has tests disagreeing with stable, so I've opted not to include any in this commit that are well-typed under the new rules.
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
force-pushed
the
match-2024-for-edition-2021
branch
from
January 27, 2025 06:16
fe072ca
to
737d409
Compare
These are very bare-bones, only intended to provide some documentation of what these feature gates are and aren't yet implementing.
This also adds `#[cfg]` attributes to tests for bindings' types, to make it visually clearer which revisions type successfully.
These are superseded by the old-edition revisions on the shared tests.
dianne
force-pushed
the
match-2024-for-edition-2021
branch
from
January 28, 2025 05:44
737d409
to
d37a4d4
Compare
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is based on #135434; only the latest 6 commits are new. It should be fully implemented, but I'll leave this as a draft until that's merged in case it needs updates.
This updates the behavior of the feature gates
ref_pat_eat_one_layer_2024_structural
andref_pat_eat_one_layer_2024
in Editions 2021 and earlier to correspond to the left and right typing rules compared here, respectively. Compared to thestable_rust
rules:&
patterns to eat&mut
reference types (and lone&mut
inherited refs) as if they're shared,&mut
patterns to eat&
reference types when there's a&mut
inherited reference to also eat,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