about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-10-27 07:19:16 -0700
committerGitHub <noreply@github.com>2016-10-27 07:19:16 -0700
commit07436946b6ee6345509b73c6e4dafb38b6a243f1 (patch)
treea56e69caf107db740137ecedaf58c9c0711d8d8d /src/libsyntax/parse
parenta0e31a5bfc9d3cf28955c4a80734f62840624641 (diff)
parentc9036ccffe30e9b05dee68fc82cbc957c983c702 (diff)
downloadrust-07436946b6ee6345509b73c6e4dafb38b6a243f1.tar.gz
rust-07436946b6ee6345509b73c6e4dafb38b6a243f1.zip
Auto merge of #37245 - goffrie:recovery, r=nrc
Recover out of an enum or struct's braced block.

If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.

Fixes #37113.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a5a081e08be..d8dff6b4aa0 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -5145,7 +5145,11 @@ impl<'a> Parser<'a> {
         let mut fields = Vec::new();
         if self.eat(&token::OpenDelim(token::Brace)) {
             while self.token != token::CloseDelim(token::Brace) {
-                fields.push(self.parse_struct_decl_field()?);
+                fields.push(self.parse_struct_decl_field().map_err(|e| {
+                    self.recover_stmt();
+                    self.eat(&token::CloseDelim(token::Brace));
+                    e
+                })?);
             }
 
             self.bump();
@@ -5673,7 +5677,11 @@ impl<'a> Parser<'a> {
         generics.where_clause = self.parse_where_clause()?;
         self.expect(&token::OpenDelim(token::Brace))?;
 
-        let enum_definition = self.parse_enum_def(&generics)?;
+        let enum_definition = self.parse_enum_def(&generics).map_err(|e| {
+            self.recover_stmt();
+            self.eat(&token::CloseDelim(token::Brace));
+            e
+        })?;
         Ok((id, ItemKind::Enum(enum_definition, generics), None))
     }