Skip to content

Commit

Permalink
Recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed May 8, 2020
1 parent 682782e commit 2209a09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/librustc_parse/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,17 @@ impl<'a> Parser<'a> {
}

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

Ok(if eq_consumed || eq_optional { Some(self.parse_expr()?) } else { None })
}

/// Parses a block. No inner attributes are allowed.
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/parser/let-binop.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn main() {
let a: i8 *= 1; //~ ERROR expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found `*=`
let a: i8 *= 1; //~ ERROR blah
let _ = a;
let b += 1;
let b += 1; //~ ERROR blah
let _ = b;
let c *= 1;
let c *= 1; //~ ERROR blah
let _ = c;
}
18 changes: 15 additions & 3 deletions src/test/ui/parser/let-binop.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found `*=`
error: blah
--> $DIR/let-binop.rs:2:15
|
LL | let a: i8 *= 1;
| ^^ expected one of 7 possible tokens
| ^^

error: aborting due to previous error
error: blah
--> $DIR/let-binop.rs:4:11
|
LL | let b += 1;
| ^^

error: blah
--> $DIR/let-binop.rs:6:11
|
LL | let c *= 1;
| ^^

error: aborting due to 3 previous errors

0 comments on commit 2209a09

Please sign in to comment.