Skip to content

Recover from C++-style "pub enum struct X" #99625

Closed
@lopopolo

Description

@lopopolo

Given the following code:

pub enum struct Range {
    Valid {
        begin: u32,
        len: u32,
    }
    Out,
}

fn main() {
    println!("Hello, world!");
}

The current output is:

   Compiling playground v0.0.1 (/playground)
error: expected identifier, found keyword `struct`
 --> src/main.rs:1:10
  |
1 | pub enum struct Range {
  |          ^^^^^^ expected identifier, found keyword

error: expected one of `<`, `where`, or `{`, found `Range`
 --> src/main.rs:1:17
  |
1 | pub enum struct Range {
  |                 ^^^^^ expected one of `<`, `where`, or `{`

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

Ideally the output should look like:

Highlight to the user that the keywords enum and struct are mutually exclusive. Replace enum struct with enum.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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