Skip to content

When given an enum E and expecting a struct S, rustc suggests using "a variant" of S. #55250

Description

@pnkfelix

Consider the following code (play):

enum E { Var1, Var2, }

struct S { base: E, }

struct Context { s: S, }

fn main() { let _c = Context { s: E::Var1 }; }

It currently yields the following diagnostic messages:

error[E0308]: mismatched types
 --> src/main.rs:7:35
  |
7 | fn main() { let _c = Context { s: E::Var1 }; }
  |                                   ^^^^^^^
  |                                   |
  |                                   expected struct `S`, found enum `E`
  |                                   help: try using a variant of the expected type: `S(E::Var1)`
  |
  = note: expected type `S`
             found type `E`

This line is what I object to:

  |                                   help: try using a variant of the expected type: `S(E::Var1)`

It has two problems:

  1. It uses the terminology variant when discussing building up an instance of the struct S.
  2. It uses a tuple struct form in the example rewrite it provides; but our S is a braced struct with named fields.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions