-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
syntax: add parser recovery for intersection- / and-patterns p1 @ p2
#65410
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29fb07d
syntax: add recovery for intersection patterns `p1 @ p2`
Centril a77a8aa
syntax: add test for intersection pattern parser recovery
Centril 72ad8f7
syntax: use `PatKind::Wild` as our `::Err` equivalent.
Centril 3a9f8de
recover_intersection_pat: adjust wording
Centril 16266a5
pprust: `p1@p2` -> `p1 @ p2`
Centril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// This tests the parser recovery in `recover_intersection_pat` | ||
// and serves as a regression test for the diagnostics issue #65400. | ||
// | ||
// The general idea is that for `$pat_lhs @ $pat_rhs` where | ||
// `$pat_lhs` is not generated by `ref? mut? $ident` we want | ||
// to suggest either switching the order or note that intersection | ||
// patterns are not allowed. | ||
|
||
fn main() { | ||
let s: Option<u8> = None; | ||
|
||
match s { | ||
Some(x) @ y => {} | ||
//~^ ERROR pattern on wrong side of `@` | ||
//~| pattern on the left, should be on the right | ||
//~| binding on the right, should be on the left | ||
//~| HELP switch the order | ||
//~| SUGGESTION y @ Some(x) | ||
_ => {} | ||
} | ||
|
||
match s { | ||
Some(x) @ Some(y) => {} | ||
//~^ ERROR left-hand side of `@` must be a binding | ||
//~| interpreted as a pattern, not a binding | ||
//~| also a pattern | ||
//~| NOTE bindings are `x`, `mut x`, `ref x`, and `ref mut x` | ||
_ => {} | ||
} | ||
|
||
match 2 { | ||
1 ..= 5 @ e => {} | ||
//~^ ERROR pattern on wrong side of `@` | ||
//~| pattern on the left, should be on the right | ||
//~| binding on the right, should be on the left | ||
//~| HELP switch the order | ||
//~| SUGGESTION e @ 1 ..=5 | ||
_ => {} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error: pattern on wrong side of `@` | ||
--> $DIR/intersection-patterns.rs:13:9 | ||
| | ||
LL | Some(x) @ y => {} | ||
| -------^^^- | ||
| | | | ||
| | binding on the right, should be on the left | ||
| pattern on the left, should be on the right | ||
| help: switch the order: `y @ Some(x)` | ||
|
||
error: left-hand side of `@` must be a binding | ||
--> $DIR/intersection-patterns.rs:23:9 | ||
| | ||
LL | Some(x) @ Some(y) => {} | ||
| -------^^^------- | ||
| | | | ||
| | also a pattern | ||
| interpreted as a pattern, not a binding | ||
| | ||
= note: bindings are `x`, `mut x`, `ref x`, and `ref mut x` | ||
|
||
error: pattern on wrong side of `@` | ||
--> $DIR/intersection-patterns.rs:32:9 | ||
| | ||
LL | 1 ..= 5 @ e => {} | ||
| -------^^^- | ||
| | | | ||
| | binding on the right, should be on the left | ||
| pattern on the left, should be on the right | ||
| help: switch the order: `e @ 1 ..=5` | ||
|
||
error: aborting due to 3 previous errors | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pnkfelix This code should be removed when #65490 is implemented / stabilized.