-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use fields in autotupling parse recovery
We introduce a new `PartialPResult`, which is like `PResult`, except instead of the `Err` value being just a `DiagnosticBuilder`, it's a tuple whose first element is of the `Ok` type and whose second element is the diagnostic-builder: this provides a way to return to callers any useful parsing work we did before hitting the error (at the cost of having to sprinkle some awkward `.map_err`s around to convert between `PResult` and `PartialPResult`). `PartialPResult` is then used for more thorough recovery when a user omits the parens from what we presume ought to have been a tuple pattern: after emitting an error for the erroneous pattern, we can continue working with the destructured fields as if the user had correctly written a tuple, potentially catching more errors in subsequent code without the user needing to recompile.
- Loading branch information
1 parent
ed6679c
commit d615130
Showing
4 changed files
with
64 additions
and
47 deletions.
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
38 changes: 13 additions & 25 deletions
38
src/test/ui/did_you_mean/issue-48492-tuple-destructure-missing-parens.stderr
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 |
---|---|---|
@@ -1,50 +1,38 @@ | ||
error: unexpected `,` in pattern | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:47:17 | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:51:17 | ||
| | ||
47 | while let b1, b2, b3 = reading_frame.next().expect("there should be a start codon") { | ||
51 | while let b1, b2, b3 = three_slice_to_tuple(reading_frame.next() | ||
| --^------- help: try adding parentheses: `(b1, b2, b3)` | ||
|
||
error: unexpected `,` in pattern | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:57:14 | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:62:14 | ||
| | ||
57 | if let b1, b2, b3 = reading_frame.next().unwrap() { | ||
62 | if let b1, b2, b3 = three_slice_to_tuple(reading_frame.next().unwrap()) { | ||
| --^------- help: try adding parentheses: `(b1, b2, b3)` | ||
|
||
error: unexpected `,` in pattern | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:62:32 | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:65:32 | ||
| | ||
62 | Nucleotide::Adenine, Nucleotide::Cytosine, _ => { | ||
65 | Nucleotide::Adenine, Nucleotide::Cytosine, _ => { | ||
| -------------------^------------------------ help: try adding parentheses: `(Nucleotide::Adenine, Nucleotide::Cytosine, _)` | ||
|
||
error: unexpected `,` in pattern | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:74:10 | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:77:10 | ||
| | ||
74 | for x, _barr_body in women.iter().map(|woman| woman.allosomes.clone()) { | ||
77 | for x, _barr_body in women.iter().map(|woman| woman.allosomes.clone()) { | ||
| -^----------- help: try adding parentheses: `(x, _barr_body)` | ||
|
||
error: unexpected `,` in pattern | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:78:10 | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:81:10 | ||
| | ||
78 | for x, y @ Allosome::Y(_) in men.iter().map(|man| man.allosomes.clone()) { | ||
81 | for x, y @ Allosome::Y(_) in men.iter().map(|man| man.allosomes.clone()) { | ||
| -^------------------- help: try adding parentheses: `(x, y @ Allosome::Y(_))` | ||
|
||
error: unexpected `,` in pattern | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:86:14 | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:89:14 | ||
| | ||
86 | let women, men: (Vec<Genome>, Vec<Genome>) = genomes.iter().cloned() | ||
89 | let women, men: (Vec<Genome>, Vec<Genome>) = genomes.iter().cloned() | ||
| -----^---- help: try adding parentheses: `(women, men)` | ||
|
||
error[E0425]: cannot find value `b2` in this scope | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:59:20 | ||
| | ||
59 | match (b1, b2, b3) { | ||
| ^^ did you mean `b1`? | ||
|
||
error[E0425]: cannot find value `b3` in this scope | ||
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:59:24 | ||
| | ||
59 | match (b1, b2, b3) { | ||
| ^^ did you mean `b1`? | ||
|
||
error: aborting due to 8 previous errors | ||
error: aborting due to 6 previous errors | ||
|