Skip to content

Suggest i += 1 when we see i++ or ++i - #88672

Merged
bors merged 16 commits into
rust-lang:masterfrom
camelid:inc-parser-sugg
Apr 3, 2022
Merged

Suggest i += 1 when we see i++ or ++i#88672
bors merged 16 commits into
rust-lang:masterfrom
camelid:inc-parser-sugg

Conversation

@camelid

@camelidcamelid commented Sep 5, 2021

Copy link
Copy Markdown
Member

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

@camelidcamelid added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Sep 5, 2021
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 5, 2021
Comment threadsrc/test/ui/parser/increment.stderr Outdated
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
@camelidcamelid added the A-parser Area: The lexing & parsing of Rust source code to an AST label Sep 5, 2021
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
@camelidcamelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2021
@rust-log-analyzer

This comment has been minimized.

Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment threadcompiler/rustc_parse/src/parser/expr.rs Outdated
Comment threadsrc/test/ui/parser/increment.stderr Outdated
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
Comment threadcompiler/rustc_parse/src/parser/diagnostics.rs Outdated
@camelid

Copy link
Copy Markdown
MemberAuthor

Is there any way this could accidentally break macros that have i++–style syntax? I tested it a bit, and I didn't find any issues, but I thought it'd be worth bringing up.

@rust-log-analyzer

This comment has been minimized.

@camelid

Copy link
Copy Markdown
MemberAuthor

(CI is just failing because I used // TODO, which was intentional so they would be resolved before this is merged.)

@apirainoapiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 13, 2021
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 3, 2021
@joelpalmerjoelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 19, 2021
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 8, 2021
@pnkfelix

Copy link
Copy Markdown
Contributor

Hi @camelid ; we visited this for triage.

It looks like you had some questions you wanted answered, but also, @estebank had a suggestion for a change they wanted to see.

What is the status on those fronts? Do you think you are stuck waiting for more feedback from @estebank, or can you make forward progress on the suggestion they provided in the meantime?

@camelid

camelid commented Nov 19, 2021

Copy link
Copy Markdown
MemberAuthor

It's been a while, but my recollection is that I implemented most of the user-facing side of what estebank suggested, but in a different way in the parser because I got stuck with the way estebank suggested. The way the change is implemented currently works pretty well, though sometimes the suggestions aren't as good as they could be. Perhaps it would be good to accept the current state of output as good enough for an "MVP PR" since it can be improved further in the future. That's of course assuming there aren't any major issues in the output.

So, in summary: I think I need estebank to see if the impl looks okay and the error output looks good enough for a first implementation.

@camelid

Copy link
Copy Markdown
MemberAuthor

@estebank could you take another look at this when you get a chance?

@bors

bors commented Dec 15, 2021

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #91933) made this pull request unmergeable. Please resolve the merge conflicts.

@camelid

Copy link
Copy Markdown
MemberAuthor

I'll wait to rebase until this is reviewed in case it needs more rebases.

@camelid

Copy link
Copy Markdown
MemberAuthor

r? @davidtwco

camelid added 10 commits March 23, 2022 22:31
This records that the suggestions are mutually-exclusive (i.e., only one
should be applied).
`run-rustfix` applies all suggestions regardless of their Applicability.
There's a flag, `rustfix-only-machine-applicable`, that does what it
says, but then the produced `.fixed` file would have invalid code from
the suggestions that weren't applied. So, I moved the cases of postfix
increment, in which case multiple suggestions are given, to the
`-notfixed` test, which does not run rustfix.
I also changed the Applicability to Unspecified since MaybeIncorrect
requires that the code be valid, even if it's incorrect.
I changed the test functions to be `pub` rather than called from a
`main` function too, for easier future modification of tests.
@camelid

Copy link
Copy Markdown
MemberAuthor

Ok, hopefully CI should pass now.

@davidtwco

Copy link
Copy Markdown
Member

This is great, thanks for seeing this through. Could you squash some of the commits? r=me after that.

@davidtwcodavidtwco added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 1, 2022
@camelid

Copy link
Copy Markdown
MemberAuthor

@davidtwco It's hard to squash without squashing all of them into one commit, and I'd rather keep the history to make it easier to understand the design choices for the code (e.g., when git blameing). Is it okay to leave it unsquashed?

@davidtwco

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Apr 3, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 4943688 has been approved by davidtwco

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 3, 2022
@bors

bors commented Apr 3, 2022

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 4943688 with merge 133859d...

@bors

bors commented Apr 3, 2022

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 133859d to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Apr 3, 2022
@bors
bors merged commit 133859d into rust-lang:masterApr 3, 2022
@rustbotrustbot added this to the 1.61.0 milestone Apr 3, 2022
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (133859d): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: no relevant changes found. 2 results were found to be statistically significant but too small to be relevant.
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count102000
mean2N/A1.4%N/AN/AN/A
maxN/A2.6%N/AN/AN/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@camelid
camelid deleted the inc-parser-sugg branch April 3, 2022 22:16
@camelid

Copy link
Copy Markdown
MemberAuthor

Thank you so much for helping me with this PR and being patient even though it took me forever to finish it! ❤️

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add diagnostic for ++ and -- usages

13 participants

@camelid@rust-log-analyzer@pnkfelix@bors@davidtwco@rust-timer@estebank@b-naber@JohnCSimon@apiraino@rust-highfive@joelpalmer@rustbot