]> git.lizzy.rs Git - rust.git/commitdiff
Recover gracefully from `struct ` parse errors
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 14 Aug 2020 04:15:36 +0000 (21:15 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Fri, 14 Aug 2020 04:15:36 +0000 (21:15 -0700)
src/librustc_parse/parser/item.rs
src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.rs
src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
src/test/ui/parser/removed-syntax-field-let.rs
src/test/ui/parser/removed-syntax-field-let.stderr

index 10d214e52abdbdda46f4b6df3de9508b5db0abcb..bba65534f1be306cd6276aea94dbe647a2b1cd6d 100644 (file)
@@ -1313,7 +1313,7 @@ fn parse_name_and_ty(
         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 {
index 0d53315839cebbd7b0d61383aba31c58163a8a39..090a17b413dda582e9ea71ff3d427f3fc66088ae 100644 (file)
@@ -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);
 }
 
index ac8dd48a588791f6f50019366a3bda2556c389c3..a47d5506ef0b83718091e55dcd14fb26afd2c27a 100644 (file)
@@ -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
 
index 9fe4a148a56aa0adb1001a32c45ac9b3d4467b06..6d64de296f15001130b56ccd8fe76f868325108a 100644 (file)
@@ -1,7 +1,6 @@
 struct S {
     let foo: (),
     //~^  ERROR expected identifier, found keyword `let`
-    //~^^ ERROR expected `:`, found `foo`
 }
 
 fn main() {}
index 7de2c730a70696ee86fd1aca3c3d9803bb0fda22..10be2e045b2b883f9626bd18e247442b4d060a7b 100644 (file)
@@ -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