diff options
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 14 | ||||
| -rw-r--r-- | tests/ui/structs-enums/recover-enum-with-bad-where.rs | 4 | ||||
| -rw-r--r-- | tests/ui/structs-enums/recover-enum-with-bad-where.stderr | 15 | 
3 files changed, 27 insertions, 6 deletions
| diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index c05479feb61..af1d1a1ec66 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -353,6 +353,20 @@ impl<'a> Parser<'a> { if !self.eat_keyword(exp!(Where)) { return Ok((where_clause, None)); } + + if self.eat_noexpect(&token::Colon) { + let colon_span = self.prev_token.span; + self.dcx() + .struct_span_err(colon_span, "unexpected colon after `where`") + .with_span_suggestion_short( + colon_span, + "remove the colon", + "", + Applicability::MachineApplicable, + ) + .emit(); + } + where_clause.has_where_token = true; let where_lo = self.prev_token.span; diff --git a/tests/ui/structs-enums/recover-enum-with-bad-where.rs b/tests/ui/structs-enums/recover-enum-with-bad-where.rs index 850ee6caa1a..cf7747d710b 100644 --- a/tests/ui/structs-enums/recover-enum-with-bad-where.rs +++ b/tests/ui/structs-enums/recover-enum-with-bad-where.rs @@ -1,6 +1,8 @@ pub enum Foo<T> where: -//~^ ERROR expected one of `#`, `{`, lifetime, or type, found `:` +//~^ ERROR unexpected colon after `where` T: Missing, {} +//~^ ERROR cannot find trait `Missing` in this scope +// (evidence that we continue parsing after the erroneous colon) fn main() {} diff --git a/tests/ui/structs-enums/recover-enum-with-bad-where.stderr b/tests/ui/structs-enums/recover-enum-with-bad-where.stderr index 6f28ff56bab..30b73f59e8c 100644 --- a/tests/ui/structs-enums/recover-enum-with-bad-where.stderr +++ b/tests/ui/structs-enums/recover-enum-with-bad-where.stderr @@ -1,10 +1,15 @@ -error: expected one of `#`, `{`, lifetime, or type, found `:` +error: unexpected colon after `where` --> $DIR/recover-enum-with-bad-where.rs:2:6 | -LL | pub enum Foo<T> - | --- while parsing this enum LL | where: - | ^ expected one of `#`, `{`, lifetime, or type + | ^ help: remove the colon -error: aborting due to 1 previous error +error[E0405]: cannot find trait `Missing` in this scope + --> $DIR/recover-enum-with-bad-where.rs:4:8 + | +LL | T: Missing, {} + | ^^^^^^^ not found in this scope + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0405`. | 
