about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-07-29 20:04:28 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-07-29 21:43:35 +0400
commitc6558c0bc71024b8aca1db317c15cdf701d917d8 (patch)
treed77c9d6f4dbf6203f11908bcd14a05555432ae8e /compiler/rustc_parse/src/parser
parente5682615bb4fdb90e3a37b810a1b7bded2a1199e (diff)
downloadrust-c6558c0bc71024b8aca1db317c15cdf701d917d8.tar.gz
rust-c6558c0bc71024b8aca1db317c15cdf701d917d8.zip
Recover keywords in bounds
For example, this fixes a error for `impl fn()` (notice the capitalization)
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/ty.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs
index 31b40a83e60..b76ba8ff2d9 100644
--- a/compiler/rustc_parse/src/parser/ty.rs
+++ b/compiler/rustc_parse/src/parser/ty.rs
@@ -640,7 +640,13 @@ impl<'a> Parser<'a> {
         let mut bounds = Vec::new();
         let mut negative_bounds = Vec::new();
 
-        while self.can_begin_bound() || self.token.is_keyword(kw::Dyn) {
+        while self.can_begin_bound()
+            // Continue even if we find a keyword.
+            // This is necessary for error recover on, for example, `impl fn()`.
+            //
+            // The only keyword that can go after generic bounds is `where`, so stop if it's it.
+            || (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))
+        {
             if self.token.is_keyword(kw::Dyn) {
                 // Account for `&dyn Trait + dyn Other`.
                 self.struct_span_err(self.token.span, "invalid `dyn` keyword")