about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2019-04-20 11:31:38 +0100
committerDavid Wood <david@davidtw.co>2019-04-20 11:36:04 +0100
commit60c6ed9664e8d6fa30388290d5fe86eb80bc6fc7 (patch)
tree54080badf103398e605f4f6dc8a7e767c2890dbe /src/libsyntax/parse
parentd6f513ec7d1e83c8689f94fb48686dd11f1d1c80 (diff)
downloadrust-60c6ed9664e8d6fa30388290d5fe86eb80bc6fc7.tar.gz
rust-60c6ed9664e8d6fa30388290d5fe86eb80bc6fc7.zip
Fix fn front matter parsing ICE from invalid code.
This commit fixes an "unreachable code" ICE that results from parsing
invalid code where the compiler is expecting the next trait item
declaration in the middle of the previous trait item due to extra
closing braces.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a5adb37f745..8e6db8a541a 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6575,7 +6575,12 @@ impl<'a> Parser<'a> {
             };
             (respan(self.prev_span, Constness::NotConst), unsafety, abi)
         };
-        self.expect_keyword(keywords::Fn)?;
+        if !self.eat_keyword(keywords::Fn) {
+            // It is possible for `expect_one_of` to recover given the contents of
+            // `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
+            // account for this.
+            if !self.expect_one_of(&[], &[])? { unreachable!() }
+        }
         Ok((constness, unsafety, asyncness, abi))
     }