Skip to content

Suggest using the enum when a variant is used as a type #35675

Closed
@Wilfred

Description

Consider the code:

enum Fruit {
    Apple(i64),
    Orange(i64),
}

fn should_return_fruit() -> Apple {
    Apple(5)
}

The current error wording is:

error[E0412]: type name `Apple` is undefined or not in scope
 --> <anon>:7:29
  |
7 | fn should_return_fruit() -> Apple {
  |                             ^^^^^ undefined or not in scope
  |
  = help: no candidates by the name of `Apple` found in your project; maybe you misspelled the name or forgot to import an external crate?

I periodically make this exact mistake. It would be really nice if rustc could spot this error and say did you mean Fruit?

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