From 2e9b45e1dd8d3a248e2aea60314787650e3abcc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 13 Aug 2020 21:15:36 -0700 Subject: [PATCH] Recover gracefully from `struct ` parse errors --- src/librustc_parse/parser/item.rs | 2 +- .../mismatched-braces/missing-close-brace-in-struct.rs | 1 - .../missing-close-brace-in-struct.stderr | 10 ++-------- src/test/ui/parser/removed-syntax-field-let.rs | 1 - src/test/ui/parser/removed-syntax-field-let.stderr | 8 +------- 5 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 10d214e52abdb..bba65534f1be3 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, ) -> 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 0d53315839ceb..090a17b413dda 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 { 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 ac8dd48a58879..a47d5506ef0b8 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 { | - 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 9fe4a148a56aa..6d64de296f150 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 7de2c730a7069..10be2e045b2b8 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