Better recovery
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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`.
|
||||
|
||||
Reference in New Issue
Block a user