about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2022-02-17 16:30:48 -0800
committerNoah Lev <camelidcamel@gmail.com>2022-03-23 22:31:57 -0700
commit4212835d993537158aa39406a489351a4efdda71 (patch)
tree25ba3362dae10825466043e4a5fd719eb27f3fca
parent29a5c363c7af619c1264c8b1e80241e503b27b47 (diff)
downloadrust-4212835d993537158aa39406a489351a4efdda71.tar.gz
rust-4212835d993537158aa39406a489351a4efdda71.zip
Add heuristic to avoid treating `x + +2` as increment
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs1
-rw-r--r--src/test/ui/associated-types/issue-36499.stderr14
-rw-r--r--src/test/ui/parser/issues/issue-88276-unary-plus.stderr14
3 files changed, 11 insertions, 18 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 8ac29c2b5f6..8c4ec8dc6e3 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -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 `+`
diff --git a/src/test/ui/associated-types/issue-36499.stderr b/src/test/ui/associated-types/issue-36499.stderr
index b49a34be98f..610798d880f 100644
--- a/src/test/ui/associated-types/issue-36499.stderr
+++ b/src/test/ui/associated-types/issue-36499.stderr
@@ -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
diff --git a/src/test/ui/parser/issues/issue-88276-unary-plus.stderr b/src/test/ui/parser/issues/issue-88276-unary-plus.stderr
index e65bac2c5cc..b26761729a8 100644
--- a/src/test/ui/parser/issues/issue-88276-unary-plus.stderr
+++ b/src/test/ui/parser/issues/issue-88276-unary-plus.stderr
@@ -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
-   |
-help: use `+= 1` instead
+   |                    ^ unexpected `+`
    |
-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