diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-09-06 16:16:52 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2022-03-23 22:31:57 -0700 |
| commit | c9cc43aa66911b38e9da68de6c2c7ee1f37911ea (patch) | |
| tree | b77280da36514533301d1fcfd278c4c8ab854041 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 5d9cd4b851f121d0bc84cab474d6c536aba207df (diff) | |
| download | rust-c9cc43aa66911b38e9da68de6c2c7ee1f37911ea.tar.gz rust-c9cc43aa66911b38e9da68de6c2c7ee1f37911ea.zip | |
Move increment checks to improve errors
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 148e0a24ec3..39d96b8a9e3 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -267,6 +267,18 @@ impl<'a> Parser<'a> { self.bump(); } + if self.prev_token == token::BinOp(token::Plus) + && self.token == token::BinOp(token::Plus) + { + let op_span = self.prev_token.span.to(self.token.span); + // Eat the second `+` + self.bump(); + // TODO: implement + let start_is_semi = false; + lhs = self.maybe_recover_from_postfix_increment(lhs, op_span, start_is_semi)?; + continue; + } + let op = op.node; // Special cases: if op == AssocOp::As { @@ -586,6 +598,19 @@ impl<'a> Parser<'a> { token::Ident(..) if this.is_mistaken_not_ident_negation() => { make_it!(this, attrs, |this, _| this.recover_not_expr(lo)) } + // Recover from `++x` + token::BinOp(token::Plus) + if this.look_ahead(1, |t| *t == token::BinOp(token::Plus)) => + { + let prev_is_semi = this.prev_token == token::Semi; + let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); + // Eat both `+`s. + this.bump(); + this.bump(); + + let operand_expr = this.parse_path_start_expr(Default::default())?; + this.maybe_recover_from_prefix_increment(operand_expr, pre_span, prev_is_semi) + } _ => return this.parse_dot_or_call_expr(Some(attrs)), } } |
