diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2020-08-14 20:07:13 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-14 20:07:13 -0700 |
| commit | e38eaf22d247644e5554d0c200e6df756e469b0a (patch) | |
| tree | 7bb376f1bd26749a2cf976e4b15c3634daf41d64 | |
| parent | 28b11abc2f336288379b6e635e65e23809616487 (diff) | |
| parent | 2e9b45e1dd8d3a248e2aea60314787650e3abcc9 (diff) | |
| download | rust-e38eaf22d247644e5554d0c200e6df756e469b0a.tar.gz rust-e38eaf22d247644e5554d0c200e6df756e469b0a.zip | |
Rollup merge of #75513 - estebank:confused-parser, r=davidtwco
Recover gracefully from `struct` parse errors Currently the parser tries to recover from finding a keyword where a field name was expected, but this causes extra knock down parse errors that are completely irrelevant. Instead, bail out early in the parsing of the field and consume the remaining tokens in the block. This can reduce output significantly. _Improvements based on the narrative in https://fasterthanli.me/articles/i-am-a-java-csharp-c-or-cplusplus-dev-time-to-do-some-rust_
5 files changed, 4 insertions, 18 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 10d214e52ab..bba65534f1b 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -1313,7 +1313,7 @@ impl<'a> Parser<'a> { vis: Visibility, attrs: Vec<Attribute>, ) -> PResult<'a, StructField> { - let name = self.parse_ident()?; + let name = self.parse_ident_common(false)?; self.expect(&token::Colon)?; let ty = self.parse_ty()?; Ok(StructField { diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs index 0d53315839c..090a17b413d 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs @@ -2,7 +2,6 @@ pub(crate) struct Bar<T> { foo: T, trait T { //~ ERROR expected identifier, found keyword `trait` -//~^ ERROR expected `:`, found `T` fn foo(&self); } diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr index ac8dd48a588..a47d5506ef0 100644 --- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr +++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr @@ -1,5 +1,5 @@ error: this file contains an unclosed delimiter - --> $DIR/missing-close-brace-in-struct.rs:14:65 + --> $DIR/missing-close-brace-in-struct.rs:13:65 | LL | pub(crate) struct Bar<T> { | - unclosed delimiter @@ -13,11 +13,5 @@ error: expected identifier, found keyword `trait` LL | trait T { | ^^^^^ expected identifier, found keyword -error: expected `:`, found `T` - --> $DIR/missing-close-brace-in-struct.rs:4:7 - | -LL | trait T { - | ^ expected `:` - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/removed-syntax-field-let.rs b/src/test/ui/parser/removed-syntax-field-let.rs index 9fe4a148a56..6d64de296f1 100644 --- a/src/test/ui/parser/removed-syntax-field-let.rs +++ b/src/test/ui/parser/removed-syntax-field-let.rs @@ -1,7 +1,6 @@ struct S { let foo: (), //~^ ERROR expected identifier, found keyword `let` - //~^^ ERROR expected `:`, found `foo` } fn main() {} diff --git a/src/test/ui/parser/removed-syntax-field-let.stderr b/src/test/ui/parser/removed-syntax-field-let.stderr index 7de2c730a70..10be2e045b2 100644 --- a/src/test/ui/parser/removed-syntax-field-let.stderr +++ b/src/test/ui/parser/removed-syntax-field-let.stderr @@ -4,11 +4,5 @@ error: expected identifier, found keyword `let` LL | let foo: (), | ^^^ expected identifier, found keyword -error: expected `:`, found `foo` - --> $DIR/removed-syntax-field-let.rs:2:9 - | -LL | let foo: (), - | ^^^ expected `:` - -error: aborting due to 2 previous errors +error: aborting due to previous error |
