Deduplicate mismatched delimiter errors

Delay unmatched delimiter errors until after the parser has run to
deduplicate them when parsing and attempt recovering intelligently.
This commit is contained in:
Esteban Küber 2019-01-27 21:04:50 -08:00
parent 825f355c74
commit 7451cd8dc0
17 changed files with 335 additions and 158 deletions

View file

@ -1,3 +1,9 @@
error: unexpected token: `;`
--> $DIR/parser-recovery-2.rs:12:15
|
LL | let x = y.; //~ ERROR unexpected token
| ^
error: incorrect close delimiter: `)`
--> $DIR/parser-recovery-2.rs:8:5
|
@ -7,12 +13,6 @@ LL | let x = foo(); //~ ERROR cannot find function `foo` in this scope
LL | ) //~ ERROR incorrect close delimiter: `)`
| ^ incorrect close delimiter
error: unexpected token: `;`
--> $DIR/parser-recovery-2.rs:12:15
|
LL | let x = y.; //~ ERROR unexpected token
| ^
error[E0425]: cannot find function `foo` in this scope
--> $DIR/parser-recovery-2.rs:7:17
|

View file

@ -5,7 +5,7 @@ pub fn trace_option(option: Option<isize>) {
option.map(|some| 42;
//~^ ERROR: expected one of
} //~ ERROR: incorrect close delimiter
}
//~^ ERROR: expected expression, found `)`
fn main() {}

View file

@ -1,25 +1,17 @@
error: incorrect close delimiter: `}`
--> $DIR/issue-10636-2.rs:8:1
|
LL | pub fn trace_option(option: Option<isize>) {
| - close delimiter possibly meant for this
LL | option.map(|some| 42;
| - un-closed delimiter
...
LL | } //~ ERROR: incorrect close delimiter
| ^ incorrect close delimiter
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> $DIR/issue-10636-2.rs:5:25
|
LL | option.map(|some| 42;
| ^ expected one of `)`, `,`, `.`, `?`, or an operator here
| - ^
| | |
| | help: `)` may belong here
| in order to close this...
error: expected expression, found `)`
--> $DIR/issue-10636-2.rs:8:1
|
LL | } //~ ERROR: incorrect close delimiter
LL | }
| ^ expected expression
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

View file

@ -1,4 +1,5 @@
fn foo() { //~ NOTE un-closed delimiter
fn foo() {
//~^ NOTE un-closed delimiter
match Some(10) {
//~^ NOTE this delimiter might not be properly closed...
Some(y) => { panic!(); }

View file

@ -1,8 +1,9 @@
error: this file contains an un-closed delimiter
--> $DIR/issue-2354.rs:15:66
--> $DIR/issue-2354.rs:16:66
|
LL | fn foo() { //~ NOTE un-closed delimiter
LL | fn foo() {
| - un-closed delimiter
LL | //~^ NOTE un-closed delimiter
LL | match Some(10) {
| - this delimiter might not be properly closed...
...
@ -16,7 +17,7 @@ error[E0601]: `main` function not found in crate `issue_2354`
|
= note: the main function must be defined at the crate level but you have one or more functions named 'main' that are not defined at the crate level. Either move the definition or attach the `#[main]` attribute to override this behavior.
note: here is a function named 'main'
--> $DIR/issue-2354.rs:14:1
--> $DIR/issue-2354.rs:15:1
|
LL | fn main() {} //~ NOTE here is a function named 'main'
| ^^^^^^^^^^^^

View file

@ -1,3 +1,9 @@
error: unexpected close delimiter: `}`
--> $DIR/macro-mismatched-delim-paren-brace.rs:5:1
|
LL | } //~ ERROR unexpected close delimiter: `}`
| ^ unexpected close delimiter
error: incorrect close delimiter: `}`
--> $DIR/macro-mismatched-delim-paren-brace.rs:4:5
|
@ -7,11 +13,5 @@ LL | bar, "baz", 1, 2.0
LL | } //~ ERROR incorrect close delimiter
| ^ incorrect close delimiter
error: unexpected close delimiter: `}`
--> $DIR/macro-mismatched-delim-paren-brace.rs:5:1
|
LL | } //~ ERROR unexpected close delimiter: `}`
| ^ unexpected close delimiter
error: aborting due to 2 previous errors

View file

@ -17,7 +17,7 @@ pub mod raw {
//~| expected type `()`
//~| found type `std::result::Result<bool, std::io::Error>`
//~| expected one of
} else { //~ ERROR: incorrect close delimiter: `}`
} else {
//~^ ERROR: expected one of
//~| unexpected token
Ok(false);

View file

@ -1,19 +1,11 @@
error: incorrect close delimiter: `}`
--> $DIR/token-error-correct-3.rs:20:9
|
LL | if !is_directory(path.as_ref()) { //~ ERROR: cannot find function `is_directory`
| - close delimiter possibly meant for this
LL | callback(path.as_ref(); //~ ERROR expected one of
| - un-closed delimiter
...
LL | } else { //~ ERROR: incorrect close delimiter: `}`
| ^ incorrect close delimiter
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> $DIR/token-error-correct-3.rs:14:35
|
LL | callback(path.as_ref(); //~ ERROR expected one of
| ^ expected one of `)`, `,`, `.`, `?`, or an operator here
| - ^
| | |
| | help: `)` may belong here
| in order to close this...
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
--> $DIR/token-error-correct-3.rs:20:9
@ -21,7 +13,7 @@ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
LL | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
| - expected one of `.`, `;`, `?`, `}`, or an operator here
...
LL | } else { //~ ERROR: incorrect close delimiter: `}`
LL | } else {
| ^ unexpected token
error[E0425]: cannot find function `is_directory` in this scope
@ -41,7 +33,7 @@ LL | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mis
= note: expected type `()`
found type `std::result::Result<bool, std::io::Error>`
error: aborting due to 5 previous errors
error: aborting due to 4 previous errors
Some errors occurred: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.

View file

@ -1,3 +1,9 @@
error: expected expression, found `;`
--> $DIR/token-error-correct.rs:4:13
|
LL | foo(bar(;
| ^ expected expression
error: incorrect close delimiter: `}`
--> $DIR/token-error-correct.rs:6:1
|
@ -9,11 +15,5 @@ LL | //~^ ERROR: expected expression, found `;`
LL | }
| ^ incorrect close delimiter
error: expected expression, found `;`
--> $DIR/token-error-correct.rs:4:13
|
LL | foo(bar(;
| ^ expected expression
error: aborting due to 2 previous errors