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

Add wrap suggestions for record variants #99986

Merged
merged 4 commits into from
Aug 1, 2022

Conversation

WaffleLapkin
Copy link
Member

This PR adds a suggestions to wrap an expression in a record struct/variant when encountering mismatched types, similarly to a suggestion to wrap expression in a tuple struct that was added before.

An example:

struct B {
    f: u8,
}

enum E {
    A(u32),
    B { f: u8 },
}

fn main() {
    let _: B = 1;
    let _: E = 1;
}
error[E0308]: mismatched types
  --> ./t.rs:11:16
   |
11 |     let _: B = 1;
   |            -   ^ expected struct `B`, found integer
   |            |
   |            expected due to this
   |
help: try wrapping the expression in `B`
   |
11 |     let _: B = B { f: 1 };
   |                ++++++   +

error[E0308]: mismatched types
  --> ./t.rs:12:16
   |
12 |     let _: E = 1;
   |            -   ^ expected enum `E`, found integer
   |            |
   |            expected due to this
   |
help: try wrapping the expression in a variant of `E`
   |
12 |     let _: E = E::A(1);
   |                +++++ +
12 |     let _: E = E::B { f: 1 };
   |                +++++++++   +

r? @compiler-errors

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 31, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2022
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

Looks great ✨

@bors r+

@bors
Copy link
Contributor

bors commented Jul 31, 2022

📌 Commit 1c2ea78 has been approved by compiler-errors

It is now in the queue for this repository.

@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 Jul 31, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 1, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#99519 (Remove implicit names and values from `--cfg` in `--check-cfg`)
 - rust-lang#99620 (`-Z location-detail`: provide option to disable all location details)
 - rust-lang#99932 (Fix unwinding on certain platforms when debug assertions are enabled)
 - rust-lang#99973 (Layout things)
 - rust-lang#99980 (Remove more Clean trait implementations)
 - rust-lang#99984 (Fix compat.rs for `cfg(miri)`)
 - rust-lang#99986 (Add wrap suggestions for record variants)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 20a5e9f into rust-lang:master Aug 1, 2022
@rustbot rustbot added this to the 1.64.0 milestone Aug 1, 2022
@WaffleLapkin WaffleLapkin deleted the record_struct_wrap_suggestion branch August 1, 2022 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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