-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest i += 1
when we see i++
or ++i
#88672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5d9cd4b
Suggest `i += 1` when we see `i++` or `++i`
camelid c9cc43a
Move increment checks to improve errors
camelid d915606
Remove error recovery todos
camelid 80e57e2
Reduce rightward drift
camelid 67a9adb
Refactor, handle fields better, add field tests
camelid 7287f92
Emit structured suggestions for field accesses too
camelid 62b8ea6
Emit both subexp and standalone sugg for postfix
camelid 073010d
Improve handling of `tmp` variable name conflicts
camelid 713a11b
Bless tests
camelid 29a5c36
Improve function names
camelid 4212835
Add heuristic to avoid treating `x + +2` as increment
camelid 95960b7
Make `standalone` an enum
camelid ef74796
Change temporary variable name if it would conflict
camelid 725cde4
Use `multipart_suggestions`
camelid 86220d6
Fix rustfix panic on test
camelid 4943688
Fix from rebase
camelid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.