-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwco
Suggest `i += 1` when we see `i++` or `++i` Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--` is tricky to handle). This is a continuation of #83536. r? `@estebank`
- Loading branch information
Showing
7 changed files
with
514 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// run-rustfix | ||
|
||
pub fn pre_regular() { | ||
let mut i = 0; | ||
i += 1; //~ ERROR Rust has no prefix increment operator | ||
println!("{}", i); | ||
} | ||
|
||
pub fn pre_while() { | ||
let mut i = 0; | ||
while { i += 1; i } < 5 { | ||
//~^ ERROR Rust has no prefix increment operator | ||
println!("{}", i); | ||
} | ||
} | ||
|
||
pub fn pre_regular_tmp() { | ||
let mut tmp = 0; | ||
tmp += 1; //~ ERROR Rust has no prefix increment operator | ||
println!("{}", tmp); | ||
} | ||
|
||
pub fn pre_while_tmp() { | ||
let mut tmp = 0; | ||
while { tmp += 1; tmp } < 5 { | ||
//~^ ERROR Rust has no prefix increment operator | ||
println!("{}", tmp); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// run-rustfix | ||
|
||
pub fn pre_regular() { | ||
let mut i = 0; | ||
++i; //~ ERROR Rust has no prefix increment operator | ||
println!("{}", i); | ||
} | ||
|
||
pub fn pre_while() { | ||
let mut i = 0; | ||
while ++i < 5 { | ||
//~^ ERROR Rust has no prefix increment operator | ||
println!("{}", i); | ||
} | ||
} | ||
|
||
pub fn pre_regular_tmp() { | ||
let mut tmp = 0; | ||
++tmp; //~ ERROR Rust has no prefix increment operator | ||
println!("{}", tmp); | ||
} | ||
|
||
pub fn pre_while_tmp() { | ||
let mut tmp = 0; | ||
while ++tmp < 5 { | ||
//~^ ERROR Rust has no prefix increment operator | ||
println!("{}", tmp); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
error: Rust has no prefix increment operator | ||
--> $DIR/increment-autofix.rs:5:5 | ||
| | ||
LL | ++i; | ||
| ^^ not a valid prefix operator | ||
| | ||
help: use `+= 1` instead | ||
| | ||
LL - ++i; | ||
LL + i += 1; | ||
| | ||
|
||
error: Rust has no prefix increment operator | ||
--> $DIR/increment-autofix.rs:11:11 | ||
| | ||
LL | while ++i < 5 { | ||
| ----- ^^ not a valid prefix operator | ||
| | | ||
| while parsing the condition of this `while` expression | ||
| | ||
help: use `+= 1` instead | ||
| | ||
LL | while { i += 1; i } < 5 { | ||
| ~ +++++++++ | ||
|
||
error: Rust has no prefix increment operator | ||
--> $DIR/increment-autofix.rs:19:5 | ||
| | ||
LL | ++tmp; | ||
| ^^ not a valid prefix operator | ||
| | ||
help: use `+= 1` instead | ||
| | ||
LL - ++tmp; | ||
LL + tmp += 1; | ||
| | ||
|
||
error: Rust has no prefix increment operator | ||
--> $DIR/increment-autofix.rs:25:11 | ||
| | ||
LL | while ++tmp < 5 { | ||
| ----- ^^ not a valid prefix operator | ||
| | | ||
| while parsing the condition of this `while` expression | ||
| | ||
help: use `+= 1` instead | ||
| | ||
LL | while { tmp += 1; tmp } < 5 { | ||
| ~ +++++++++++ | ||
|
||
error: aborting due to 4 previous errors | ||
|
Oops, something went wrong.