Skip to content

Commit e639212

Browse files
Make recovery for enum with struct field a bit more accurate
1 parent 94e9973 commit e639212

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,8 @@ impl<'a> Parser<'a> {
15521552
})
15531553
.map_err(|mut err| {
15541554
err.span_label(ident.span, "while parsing this enum");
1555-
if self.token == token::Colon {
1555+
// Try to recover `enum Foo { ident : Ty }`.
1556+
if self.prev_token.is_non_reserved_ident() && self.token == token::Colon {
15561557
let snapshot = self.create_snapshot_for_diagnostic();
15571558
self.bump();
15581559
match self.parse_ty() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub enum Foo<T>
2+
where:
3+
//~^ ERROR expected one of `#`, `{`, lifetime, or type, found `:`
4+
T: Missing, {}
5+
6+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `#`, `{`, lifetime, or type, found `:`
2+
--> $DIR/recover-enum-with-bad-where.rs:2:6
3+
|
4+
LL | pub enum Foo<T>
5+
| --- while parsing this enum
6+
LL | where:
7+
| ^ expected one of `#`, `{`, lifetime, or type
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)