mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
Add heuristic to avoid treating x + +2
as increment
This commit is contained in:
parent
29a5c363c7
commit
4212835d99
@ -269,6 +269,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
if self.prev_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);
|
||||
// Eat the second `+`
|
||||
|
@ -1,17 +1,13 @@
|
||||
error: Rust has no postfix increment operator
|
||||
--> $DIR/issue-36499.rs:4:7
|
||||
error: leading `+` is not supported
|
||||
--> $DIR/issue-36499.rs:4:9
|
||||
|
|
||||
LL | 2 + +2;
|
||||
| ^^^ not a valid postfix operator
|
||||
| ^ unexpected `+`
|
||||
|
|
||||
help: use `+= 1` instead
|
||||
|
|
||||
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
|
||||
help: try removing the `+`
|
||||
|
|
||||
LL - 2 + +2;
|
||||
LL + 2 += 12;
|
||||
LL + 2 + 2;
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -10,20 +10,16 @@ LL - let _ = +1;
|
||||
LL + let _ = 1;
|
||||
|
|
||||
|
||||
error: Rust has no postfix increment operator
|
||||
--> $DIR/issue-88276-unary-plus.rs:5:18
|
||||
error: leading `+` is not supported
|
||||
--> $DIR/issue-88276-unary-plus.rs:5:20
|
||||
|
|
||||
LL | let _ = (1.0 + +2.0) * +3.0;
|
||||
| ^^^ not a valid postfix operator
|
||||
| ^ unexpected `+`
|
||||
|
|
||||
help: use `+= 1` instead
|
||||
|
|
||||
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
|
||||
help: try removing the `+`
|
||||
|
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user