Skip to content

Commit 2209a09

Browse files
committed
Recovery
1 parent 682782e commit 2209a09

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/librustc_parse/parser/stmt.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,17 @@ impl<'a> Parser<'a> {
216216
}
217217

218218
/// Parses the RHS of a local variable declaration (e.g., '= 14;').
219-
fn parse_initializer(&mut self, skip_eq: bool) -> PResult<'a, Option<P<Expr>>> {
220-
if self.eat(&token::Eq) || skip_eq { Ok(Some(self.parse_expr()?)) } else { Ok(None) }
219+
fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<P<Expr>>> {
220+
let eq_consumed = match self.token.kind {
221+
token::BinOpEq(..) => {
222+
self.struct_span_err(self.token.span, "blah").emit();
223+
self.bump();
224+
true
225+
}
226+
_ => self.eat(&token::Eq),
227+
};
228+
229+
Ok(if eq_consumed || eq_optional { Some(self.parse_expr()?) } else { None })
221230
}
222231

223232
/// Parses a block. No inner attributes are allowed.

src/test/ui/parser/let-binop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
2-
let a: i8 *= 1; //~ ERROR expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found `*=`
2+
let a: i8 *= 1; //~ ERROR blah
33
let _ = a;
4-
let b += 1;
4+
let b += 1; //~ ERROR blah
55
let _ = b;
6-
let c *= 1;
6+
let c *= 1; //~ ERROR blah
77
let _ = c;
88
}

src/test/ui/parser/let-binop.stderr

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found `*=`
1+
error: blah
22
--> $DIR/let-binop.rs:2:15
33
|
44
LL | let a: i8 *= 1;
5-
| ^^ expected one of 7 possible tokens
5+
| ^^
66

7-
error: aborting due to previous error
7+
error: blah
8+
--> $DIR/let-binop.rs:4:11
9+
|
10+
LL | let b += 1;
11+
| ^^
12+
13+
error: blah
14+
--> $DIR/let-binop.rs:6:11
15+
|
16+
LL | let c *= 1;
17+
| ^^
18+
19+
error: aborting due to 3 previous errors
820

0 commit comments

Comments
 (0)