syntax: add parser recovery for intersection- / and-patterns p1 @ p2#65410
Merged
bors merged 5 commits intorust-lang:masterfrom Oct 15, 2019
Merged
syntax: add parser recovery for intersection- / and-patterns p1 @ p2#65410bors merged 5 commits intorust-lang:masterfrom
p1 @ p2#65410bors merged 5 commits intorust-lang:masterfrom
Conversation
davidtwco
approved these changes
Oct 14, 2019
Member
There was a problem hiding this comment.
LGTM, r=me w/ @petrochenkov's comment and passing CI.
varkor
reviewed
Oct 14, 2019
tesuji
reviewed
Oct 14, 2019
Contributor
Author
|
@davidtwco Threw in two additional commits to address @varkor's review. Please take a look. :) |
davidtwco
approved these changes
Oct 14, 2019
Contributor
|
@bors r=davidtwco,varkor |
Collaborator
|
📌 Commit 16266a5 has been approved by |
tmandry
added a commit
to tmandry/rust
that referenced
this pull request
Oct 15, 2019
…=davidtwco,varkor syntax: add parser recovery for intersection- / and-patterns `p1 @ p2` Fixes rust-lang#65400. The recovery comes in two flavors: 1. We know that `p2` is a binding so we can invert as `p2 @ p1`: ```rust error: pattern on wrong side of `@` --> $DIR/intersection-patterns.rs:13:9 | LL | Some(x) @ y => {} | -------^^^- | | | | | binding on the right, should be to the left | pattern on the left, should be to the right | help: switch the order: `y @ Some(x)` ``` 2. Otherwise we emit a generic diagnostic for the lack of support for intersection patterns: ```rust 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` ``` For more on and-patterns, see e.g. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching#and-pattern. r? @davidtwco cc @varkor @lzutao
bors
added a commit
that referenced
this pull request
Oct 15, 2019
Rollup of 10 pull requests Successful merges: - #65170 (rustc_metadata: Privatize private code and remove dead code) - #65260 (Optimize `LexicalResolve::expansion`.) - #65261 (Remove `Option` from `TokenStream`) - #65332 (std::fmt: reorder docs) - #65340 (Several changes to the codegen backend organization) - #65365 (Include const generic arguments in metadata) - #65398 (Bring attention to suggestions when the only difference is capitalization) - #65410 (syntax: add parser recovery for intersection- / and-patterns `p1 @ p2`) - #65415 (Remove an outdated test output file) - #65416 (Minor sync changes) Failed merges: r? @ghost
Centril
commented
Oct 19, 2019
| // The user inverted the order, so help them fix that. | ||
| let mut applicability = Applicability::MachineApplicable; | ||
| lhs.walk(&mut |p| match p.kind { | ||
| // `check_match` is unhappy if the subpattern has a binding anywhere. |
Contributor
Author
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #65400.
The recovery comes in two flavors:
p2is a binding so we can invert asp2 @ p1:For more on and-patterns, see e.g. https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching#and-pattern.
r? @davidtwco
cc @varkor @lzutao