Skip to content

"No variant named VariantName" when using Self::Variant syntax #55157

Closed
@cramertj

Description

@cramertj
enum Foo {
    Bar
}

impl Foo {
    fn foo() -> Self {
        Self::Bar
    }
}

gives the error

error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
 --> src/main.rs:7:9
  |
1 | enum Foo {
  | -------- variant `Bar` not found here
...
7 |         Self::Bar
  |         ^^^^^^^^^ variant not found in `Foo`
  |
  = note: did you mean `Foo::Bar`?

error: aborting due to previous error

The "variant not found" bit is nonsense.

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