about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-04-21 07:20:14 +0000
committerbors <bors@rust-lang.org>2019-04-21 07:20:14 +0000
commit4d9c6cd7226e1839a195f1b6e7d40a3ccf9bb062 (patch)
tree57987160b517735c1654f387d18b1c24b35a4788 /src/libsyntax/parse/parser.rs
parent9224be5fa39f6170f6e046342976efee5453a1ff (diff)
parent60c6ed9664e8d6fa30388290d5fe86eb80bc6fc7 (diff)
downloadrust-4d9c6cd7226e1839a195f1b6e7d40a3ccf9bb062.tar.gz
rust-4d9c6cd7226e1839a195f1b6e7d40a3ccf9bb062.zip
Auto merge of #60132 - davidtwco:issue-60075, r=estebank
Fix fn front matter parsing ICE from invalid code.

Fixes #60075.

This PR 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.

r? @estebank (thanks for the minimized test case)
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-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 8feab373e71..29d2d2ad73d 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -6618,7 +6618,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))
     }