Skip to content

Commit c6558c0

Browse files
committedJul 29, 2022
Recover keywords in bounds
For example, this fixes a error for `impl fn()` (notice the capitalization)
1 parent e568261 commit c6558c0

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed
 

‎compiler/rustc_parse/src/parser/ty.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,13 @@ impl<'a> Parser<'a> {
640640
let mut bounds = Vec::new();
641641
let mut negative_bounds = Vec::new();
642642

643-
while self.can_begin_bound() || self.token.is_keyword(kw::Dyn) {
643+
while self.can_begin_bound()
644+
// Continue even if we find a keyword.
645+
// This is necessary for error recover on, for example, `impl fn()`.
646+
//
647+
// The only keyword that can go after generic bounds is `where`, so stop if it's it.
648+
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))
649+
{
644650
if self.token.is_keyword(kw::Dyn) {
645651
// Account for `&dyn Trait + dyn Other`.
646652
self.struct_span_err(self.token.span, "invalid `dyn` keyword")

‎src/test/ui/rfc-2632-const-trait-impl/without-tilde.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
#![feature(const_trait_impl)]
44

55
struct S<T: const Tr>;
6-
//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path
6+
//~^ ERROR expected identifier, found keyword `const`
7+
//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found keyword `const`
1+
error: expected identifier, found keyword `const`
22
--> $DIR/without-tilde.rs:5:13
33
|
44
LL | struct S<T: const Tr>;
5-
| ^^^^^ expected one of 10 possible tokens
5+
| ^^^^^ expected identifier, found keyword
66

7-
error: aborting due to previous error
7+
error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
8+
--> $DIR/without-tilde.rs:5:19
9+
|
10+
LL | struct S<T: const Tr>;
11+
| ^^ expected one of 7 possible tokens
12+
13+
error: aborting due to 2 previous errors
814

0 commit comments

Comments
 (0)
Please sign in to comment.