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

Using a type alias on an enum prevents using that enum's variants as the values for other enum variants, with "error: constant evaluation error: unresolved path in constant expression" #30936

Closed
bstrie opened this issue Jan 15, 2016 · 8 comments

Comments

@bstrie
Copy link
Contributor

bstrie commented Jan 15, 2016

Here is a program that works just fine:

enum Foo {
    Foofoo = 0
}

enum Bar {
    Barbar = Foo::Foofoo as isize
}

fn main() {}

Here is that same program with a seemingly spurious error:

enum Foo {
    Foofoo = 0
}

type Qux = Foo;

enum Bar {
    Barbar = Qux::Foofoo as isize
}

fn main() {}

Error:

<anon>:8:14: 8:25 error: constant evaluation error: unresolved path in constant expression [E0080]
<anon>:8     Barbar = Qux::Foofoo as isize
                      ^~~~~~~~~~~
@moretea
Copy link

moretea commented Jan 15, 2016

Encountered this bug when using bindgen. Bindgen produces the following code for a C enum:

pub enum Enum_Unnamed1 {
    SDL_AUDIO_STOPPED = 0,
    SDL_AUDIO_PLAYING = 1,
    SDL_AUDIO_PAUSED = 2,
}
pub type SDL_AudioStatus = Enum_Unnamed1;

@moretea
Copy link

moretea commented Jan 15, 2016

This also fails when crate boundaries are crossed, see this example crate.

@arielb1
Copy link
Contributor

arielb1 commented Jan 15, 2016

Not sure how much of a bug this is.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 16, 2016

@moretea the crate boundary issue is already reported here: #24469

@bstrie
Copy link
Contributor Author

bstrie commented Jan 18, 2016

@arielb1 I understand that type does not currently serve as a 100% transparent alias, but I was under the impression that such limitations were viewed as unfortunate accidents of the current implementation rather than deliberate design choices. For what reason would this not be a bug?

@arielb1
Copy link
Contributor

arielb1 commented Jan 25, 2016

The confusing thing is that enum variants are not associated items - because of historical reasons we are stuck with - and therefore don't work with type (or <Type> syntax, or whatever): this is basically the same reason type does not import a tuple-like struct constructor. We may want to change this.

@nodakai
Copy link
Contributor

nodakai commented Feb 10, 2016

Possible duplicate of #26264

@alexcrichton
Copy link
Member

Ah yes, looks to be a dupe of #26264 indeed!

steveklabnik added a commit to steveklabnik/rust that referenced this issue Mar 8, 2016
…, r=nikomatsakis

reference.md: clarify the limitation of type alias on an enum

Tentatively define the current behavior as the specification.

Cf. rust-lang#26264, rust-lang#28556, rust-lang#30936
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

6 participants