will not suggest for postfix operator when can not handle precedences well
This commit is contained in:
parent
dee85a391f
commit
ded10a13d2
@ -1316,7 +1316,11 @@ impl<'a> Parser<'a> {
|
|||||||
self.prefix_inc_dec_suggest(base_src, kind, spans).emit(&mut err)
|
self.prefix_inc_dec_suggest(base_src, kind, spans).emit(&mut err)
|
||||||
}
|
}
|
||||||
UnaryFixity::Post => {
|
UnaryFixity::Post => {
|
||||||
self.postfix_inc_dec_suggest(base_src, kind, spans).emit(&mut err)
|
// won't suggest since we can not handle the precedences
|
||||||
|
// for example: `a + b++` has been parsed (a + b)++ and we can not suggest here
|
||||||
|
if !matches!(base.kind, ExprKind::Binary(_, _, _)) {
|
||||||
|
self.postfix_inc_dec_suggest(base_src, kind, spans).emit(&mut err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ fn test3() {
|
|||||||
fn test4() {
|
fn test4() {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let _ = i + i++; //~ ERROR Rust has no postfix increment operator
|
let _ = i + i++; //~ ERROR Rust has no postfix increment operator
|
||||||
|
// won't suggest since we can not handle the precedences
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test5() {
|
fn test5() {
|
||||||
@ -38,4 +39,14 @@ fn test8() {
|
|||||||
let _ = i++ + ++i; //~ ERROR Rust has no postfix increment operator
|
let _ = i++ + ++i; //~ ERROR Rust has no postfix increment operator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test9() {
|
||||||
|
let mut i = 0;
|
||||||
|
let _ = (1 + 2 + i)++; //~ ERROR Rust has no postfix increment operator
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test10() {
|
||||||
|
let mut i = 0;
|
||||||
|
let _ = (i++ + 1) + 2; //~ ERROR Rust has no postfix increment operator
|
||||||
|
}
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
@ -36,14 +36,9 @@ error: Rust has no postfix increment operator
|
|||||||
|
|
|
|
||||||
LL | let _ = i + i++;
|
LL | let _ = i + i++;
|
||||||
| ^^ not a valid postfix operator
|
| ^^ not a valid postfix operator
|
||||||
|
|
|
||||||
help: use `+= 1` instead
|
|
||||||
|
|
|
||||||
LL | let _ = { let tmp = i + i; i + i += 1; tmp };
|
|
||||||
| +++++++++++ ~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error: Rust has no postfix increment operator
|
error: Rust has no postfix increment operator
|
||||||
--> $DIR/issue-104867-inc-dec-2.rs:23:14
|
--> $DIR/issue-104867-inc-dec-2.rs:24:14
|
||||||
|
|
|
|
||||||
LL | let _ = i++ + i;
|
LL | let _ = i++ + i;
|
||||||
| ^^ not a valid postfix operator
|
| ^^ not a valid postfix operator
|
||||||
@ -54,7 +49,7 @@ LL | let _ = { let tmp = i; i += 1; tmp } + i;
|
|||||||
| +++++++++++ ~~~~~~~~~~~~~~~
|
| +++++++++++ ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: Rust has no postfix increment operator
|
error: Rust has no postfix increment operator
|
||||||
--> $DIR/issue-104867-inc-dec-2.rs:28:14
|
--> $DIR/issue-104867-inc-dec-2.rs:29:14
|
||||||
|
|
|
|
||||||
LL | let _ = i++ + i++;
|
LL | let _ = i++ + i++;
|
||||||
| ^^ not a valid postfix operator
|
| ^^ not a valid postfix operator
|
||||||
@ -65,7 +60,7 @@ LL | let _ = { let tmp = i; i += 1; tmp } + i++;
|
|||||||
| +++++++++++ ~~~~~~~~~~~~~~~
|
| +++++++++++ ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: Rust has no prefix increment operator
|
error: Rust has no prefix increment operator
|
||||||
--> $DIR/issue-104867-inc-dec-2.rs:33:13
|
--> $DIR/issue-104867-inc-dec-2.rs:34:13
|
||||||
|
|
|
|
||||||
LL | let _ = ++i + i++;
|
LL | let _ = ++i + i++;
|
||||||
| ^^ not a valid prefix operator
|
| ^^ not a valid prefix operator
|
||||||
@ -76,7 +71,7 @@ LL | let _ = { i += 1; i } + i++;
|
|||||||
| ~ +++++++++
|
| ~ +++++++++
|
||||||
|
|
||||||
error: Rust has no postfix increment operator
|
error: Rust has no postfix increment operator
|
||||||
--> $DIR/issue-104867-inc-dec-2.rs:38:14
|
--> $DIR/issue-104867-inc-dec-2.rs:39:14
|
||||||
|
|
|
|
||||||
LL | let _ = i++ + ++i;
|
LL | let _ = i++ + ++i;
|
||||||
| ^^ not a valid postfix operator
|
| ^^ not a valid postfix operator
|
||||||
@ -86,5 +81,27 @@ help: use `+= 1` instead
|
|||||||
LL | let _ = { let tmp = i; i += 1; tmp } + ++i;
|
LL | let _ = { let tmp = i; i += 1; tmp } + ++i;
|
||||||
| +++++++++++ ~~~~~~~~~~~~~~~
|
| +++++++++++ ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to 8 previous errors
|
error: Rust has no postfix increment operator
|
||||||
|
--> $DIR/issue-104867-inc-dec-2.rs:44:24
|
||||||
|
|
|
||||||
|
LL | let _ = (1 + 2 + i)++;
|
||||||
|
| ^^ not a valid postfix operator
|
||||||
|
|
|
||||||
|
help: use `+= 1` instead
|
||||||
|
|
|
||||||
|
LL | let _ = { let tmp = (1 + 2 + i); (1 + 2 + i) += 1; tmp };
|
||||||
|
| +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: Rust has no postfix increment operator
|
||||||
|
--> $DIR/issue-104867-inc-dec-2.rs:49:15
|
||||||
|
|
|
||||||
|
LL | let _ = (i++ + 1) + 2;
|
||||||
|
| ^^ not a valid postfix operator
|
||||||
|
|
|
||||||
|
help: use `+= 1` instead
|
||||||
|
|
|
||||||
|
LL | let _ = ({ let tmp = i; i += 1; tmp } + 1) + 2;
|
||||||
|
| +++++++++++ ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 10 previous errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user