1
Fork 0

Add heuristic to avoid treating x + +2 as increment

This commit is contained in:
Noah Lev 2022-02-17 16:30:48 -08:00
parent 29a5c363c7
commit 4212835d99
3 changed files with 11 additions and 18 deletions

View file

@ -269,6 +269,7 @@ impl<'a> Parser<'a> {
if self.prev_token == token::BinOp(token::Plus) if self.prev_token == token::BinOp(token::Plus)
&& self.token == token::BinOp(token::Plus) && self.token == token::BinOp(token::Plus)
&& self.prev_token.span.between(self.token.span).is_empty()
{ {
let op_span = self.prev_token.span.to(self.token.span); let op_span = self.prev_token.span.to(self.token.span);
// Eat the second `+` // Eat the second `+`

View file

@ -1,17 +1,13 @@
error: Rust has no postfix increment operator error: leading `+` is not supported
--> $DIR/issue-36499.rs:4:7 --> $DIR/issue-36499.rs:4:9
| |
LL | 2 + +2; LL | 2 + +2;
| ^^^ not a valid postfix operator | ^ unexpected `+`
| |
help: use `+= 1` instead help: try removing the `+`
|
LL | { let tmp = 2 ; 2 += 1; tmp }2;
| +++++++++++ ~~~~~~~~~~~~~~~
help: or, if you don't need to use it as an expression, change it to this
| |
LL - 2 + +2; LL - 2 + +2;
LL + 2 += 12; LL + 2 + 2;
| |
error: aborting due to previous error error: aborting due to previous error

View file

@ -10,20 +10,16 @@ LL - let _ = +1;
LL + let _ = 1; LL + let _ = 1;
| |
error: Rust has no postfix increment operator error: leading `+` is not supported
--> $DIR/issue-88276-unary-plus.rs:5:18 --> $DIR/issue-88276-unary-plus.rs:5:20
| |
LL | let _ = (1.0 + +2.0) * +3.0; LL | let _ = (1.0 + +2.0) * +3.0;
| ^^^ not a valid postfix operator | ^ unexpected `+`
| |
help: use `+= 1` instead help: try removing the `+`
|
LL | let _ = ({ let tmp = 1.0 ; 1.0 += 1; tmp }2.0) * +3.0;
| +++++++++++ ~~~~~~~~~~~~~~~~~
help: or, if you don't need to use it as an expression, change it to this
| |
LL - let _ = (1.0 + +2.0) * +3.0; LL - let _ = (1.0 + +2.0) * +3.0;
LL + let _ = (1.0 += 12.0) * +3.0; LL + let _ = (1.0 + 2.0) * +3.0;
| |
error: leading `+` is not supported error: leading `+` is not supported