Recover keywords in bounds

For example, this fixes a error for `impl fn()` (notice the capitalization)
This commit is contained in:
Maybe Waffle 2022-07-29 20:04:28 +04:00
parent e5682615bb
commit c6558c0bc7
3 changed files with 18 additions and 5 deletions

View file

@ -640,7 +640,13 @@ impl<'a> Parser<'a> {
let mut bounds = Vec::new(); let mut bounds = Vec::new();
let mut negative_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) { if self.token.is_keyword(kw::Dyn) {
// Account for `&dyn Trait + dyn Other`. // Account for `&dyn Trait + dyn Other`.
self.struct_span_err(self.token.span, "invalid `dyn` keyword") self.struct_span_err(self.token.span, "invalid `dyn` keyword")

View file

@ -3,4 +3,5 @@
#![feature(const_trait_impl)] #![feature(const_trait_impl)]
struct S<T: const Tr>; struct S<T: const Tr>;
//~^ ERROR expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path //~^ ERROR expected identifier, found keyword `const`
//~| ERROR expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`

View file

@ -1,8 +1,14 @@
error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found keyword `const` error: expected identifier, found keyword `const`
--> $DIR/without-tilde.rs:5:13 --> $DIR/without-tilde.rs:5:13
| |
LL | struct S<T: const Tr>; LL | struct S<T: const Tr>;
| ^^^^^ expected one of 10 possible tokens | ^^^^^ expected identifier, found keyword
error: aborting due to previous error error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `Tr`
--> $DIR/without-tilde.rs:5:19
|
LL | struct S<T: const Tr>;
| ^^ expected one of 7 possible tokens
error: aborting due to 2 previous errors