Skip to content

Error message when defining enum using struct syntax #103869

Closed
@rdfriese

Description

@rdfriese

Although I know Enums take to form of:

enum VecOrMap{
    Vec(Vec<usize>),
    Map(HashMap<String,usize>)
}

I sometimes find myself accidentally defining them as I would a Struct (playground):

enum VecOrMap{
    vec: Vec<usize>,
    map: HashMap<String,usize>
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected one of `(`, `,`, `=`, `{`, or `}`, found `:`
 --> src/lib.rs:2:8
  |
2 |     vec: Vec<usize>,
  |        ^ expected one of `(`, `,`, `=`, `{`, or `}`

error: expected item, found `:`
 --> src/lib.rs:2:8
  |
2 |     vec: Vec<usize>,
  |        ^ expected item

error: could not compile `playground` due to 2 previous errors

This always takes more than a few seconds to parse and then realize my mistake.
Is it possible to change this to something like:

It looks like you are trying to define an Enum using Struct syntax, change `vec: Vec<usize>` to `Vec(Vec<usize>)`

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions