diff options
| author | nx2k3 <nx2k3@duck.com> | 2023-02-27 13:25:03 +0000 |
|---|---|---|
| committer | nx2k3 <nx2k3@duck.com> | 2023-02-27 13:25:03 +0000 |
| commit | 0883973d2a1a0346832e1d8556997f771c87e5d7 (patch) | |
| tree | 5d5842e18c59b8299fbc2463a2c5290fd4e6a0a5 /compiler/rustc_parse/src | |
| parent | 13a741afaccf03a4e98bedfc09e46c72e22810e0 (diff) | |
| download | rust-0883973d2a1a0346832e1d8556997f771c87e5d7.tar.gz rust-0883973d2a1a0346832e1d8556997f771c87e5d7.zip | |
check double negation
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index a14f576eedc..d1dc4ce1e99 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -284,6 +284,7 @@ impl<'a> Parser<'a> { if self.prev_token == token::BinOp(token::Minus) && self.token == token::BinOp(token::Minus) && self.prev_token.span.between(self.token.span).is_empty() + && !self.look_ahead(1, |tok| tok.can_begin_expr()) { let op_span = self.prev_token.span.to(self.token.span); // Eat the second `-` @@ -560,7 +561,10 @@ impl<'a> Parser<'a> { token::Not => make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Not)), // `~expr` token::Tilde => make_it!(this, attrs, |this, _| this.recover_tilde_expr(lo)), - + // // `-expr` + // token::BinOp(token::Minus) => { + // make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Neg)) + // } // `*expr` token::BinOp(token::Star) => { make_it!(this, attrs, |this, _| this.parse_unary_expr(lo, UnOp::Deref)) @@ -604,17 +608,20 @@ impl<'a> Parser<'a> { } // Recover from `--x`: token::BinOp(token::Minus) - if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) => + if this.look_ahead(1, |t| *t == token::BinOp(token::Minus)) + && !this.token.can_begin_expr() => { let starts_stmt = this.prev_token == token::Semi || this.prev_token == token::CloseDelim(Delimiter::Brace); let pre_span = this.token.span.to(this.look_ahead(1, |t| t.span)); + // if !this.token.can_begin_expr() { // Eat both `-`s. this.bump(); this.bump(); - let operand_expr = this.parse_dot_or_call_expr(Default::default())?; this.recover_from_prefix_decrement(operand_expr, pre_span, starts_stmt) + + // } } // `-expr` token::BinOp(token::Minus) => { |
