Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Self' cannot be used in enums #49636

Closed
anirudhb opened this issue Apr 4, 2018 · 1 comment
Closed

'Self' cannot be used in enums #49636

anirudhb opened this issue Apr 4, 2018 · 1 comment

Comments

@anirudhb
Copy link
Contributor

anirudhb commented Apr 4, 2018

I am trying to create a method on an enum, like this:

enum Foo {
    Bar(String),
    Baz
}

impl Foo {
    pub fn get_bar(self) -> Option<String> {
        match self {
//          vvvv error occurs
            Self::Bar(s) => Some(s),
            _ => None,
        }
    }
}

An error occurs: No variant named 'Bar' found for type 'foo::Foo' in the current scope

Is this intended behavior? If so, it should be made more clear. At least provide a better error message.
Honestly, if this isn't "implemented" yet, then it should be because it would make a better user experience.

edit (x2): formatting

@petrochenkov
Copy link
Contributor

Duplicate of #26264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants