Rust: "No variant named `VariantName`" when using Self::Variant syntax

Created on 17 Oct 2018  路  3Comments  路  Source: rust-lang/rust

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.

A-diagnostics

Most helpful comment

Based on @estebank's comment, this seems to be resolved.

All 3 comments

Latest output:

error: enum variants on type aliases are experimental
 --> file.rs:7:9
  |
7 |         Self::Bar
  |         ^^^^^^^^^
  |
  = help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable

Based on @estebank's comment, this seems to be resolved.

Was this page helpful?
0 / 5 - 0 ratings