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_
This commit is contained in:
commit
e38eaf22d2
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
struct S {
|
||||
let foo: (),
|
||||
//~^ ERROR expected identifier, found keyword `let`
|
||||
//~^^ ERROR expected `:`, found `foo`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user