Skip to content
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

Suggest wrapping patterns in enum variants #95386

Merged
merged 3 commits into from
Mar 29, 2022

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Mar 27, 2022

Structured suggestion to wrap a pattern in a single-field enum or struct:

 struct A;

 enum B {
   A(A),
 }

 fn main(b: B) {
   match b {
-    A => {}
+    B::A(A) => {}
   }
 }

Half of #94942, the other half I'm not exactly sure how to fix.

Also includes two drive-by changes (that I am open to splitting out into another PR, but thought they could be rolled up into this one):

  • 07776c1: Makes sure not to suggest wrapping if it doesn't have tuple field constructor (i.e. has named fields)
  • 8f2bbb18fd53e5008bb488302dbd354577698ede: Also suggest wrapping expressions in a tuple struct (not just enum variants)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 27, 2022
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 27, 2022
@compiler-errors compiler-errors changed the title Suggest wrapping Suggest wrapping patterns in enum variants Mar 27, 2022
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Mar 28, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Mar 29, 2022

nice!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 29, 2022

📌 Commit fc289a0 has been approved by oli-obk

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2022
Rollup of 4 pull requests

Successful merges:

 - rust-lang#93840 (Stabilize Termination and ExitCode)
 - rust-lang#95256 (Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafe)
 - rust-lang#95386 (Suggest wrapping patterns in enum variants)
 - rust-lang#95437 (diagnostics: regression test for derive bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a0d2862 into rust-lang:master Mar 29, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 29, 2022
@compiler-errors compiler-errors deleted the try-wrapping branch April 7, 2022 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant 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.

6 participants