Skip to content

Commit

Permalink
Recover gracefully from struct parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Aug 14, 2020
1 parent 3df25ae commit 2e9b45e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

1 change: 0 additions & 1 deletion src/test/ui/parser/removed-syntax-field-let.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
struct S {
let foo: (),
//~^ ERROR expected identifier, found keyword `let`
//~^^ ERROR expected `:`, found `foo`
}

fn main() {}
8 changes: 1 addition & 7 deletions src/test/ui/parser/removed-syntax-field-let.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2e9b45e

Please sign in to comment.