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

External enums are not constant #24469

Closed
thelink2012 opened this issue Apr 15, 2015 · 3 comments
Closed

External enums are not constant #24469

thelink2012 opened this issue Apr 15, 2015 · 3 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@thelink2012
Copy link

I'm not entirely sure this issue is by design of the language or really a bug, but it feels quite limiting.

When trying to use a enum variant from a external crate on a constant expression rustc fails telling it's not a constant expression although it works fine when it's in the same crate.

Example

Since it involves crates and such it's complicated to post the code only, so here's a project on which the issue can be reproduced easily by just running cargo build:
https://dl.dropboxusercontent.com/u/35476123/Releases/tmp/rust-exenum.tar
main_nope.rs tries to use a external enum in a constant expression and fails to compile.
main_works.rs tries to use a enum from the same crate in a constant expression and works.
You can switch between those two mains in Cargo.toml.

excrate/lib.rs

#[repr(i32)]
pub enum CEnum {
    Value1 = 1,
    Value2 = 2,
}

main_nope.rs

extern crate excrate;
use excrate::CEnum;

#[repr(i32)]
pub enum Enum {
    Value1 = CEnum::Value1 as i32,
    Value2 = CEnum::Value2 as i32,
}

fn main() {
}

main_works.rs


mod excrate {
    #[repr(i32)]
    pub enum CEnum {
        Value1 = 1,
        Value2 = 2,
    }
}
use excrate::CEnum;

#[repr(i32)]
pub enum Enum {
    Value1 = CEnum::Value1 as i32,
    Value2 = CEnum::Value2 as i32,
}

fn main() {
}

Meta

PS C:\Users\LINK\Desktop\rust-test> cargo build --verbose
   Compiling test v0.0.1 (file:///C:/Users/LINK/Desktop/rust-test)
     Running `rustc main_nope.rs --crate-name test --crate-type bin -g --out-dir C:\Users\LINK\Desktop\rust-test\target\
debug --emit=dep-info,link -L dependency=C:\Users\LINK\Desktop\rust-test\target\debug -L dependency=C:\Users\LINK\Deskto
p\rust-test\target\debug\deps --extern excrate=C:\Users\LINK\Desktop\rust-test\target\debug\deps\libexcrate-aed1a7b0d1e3
20a1.rlib`
       Fresh excrate v0.0.1 (file:///C:/Users/LINK/Desktop/rust-test)
main_nope.rs:6:14: 6:27 error: constant evaluation error: non-constant path in constant expr [E0080]
main_nope.rs:6     Value1 = CEnum::Value1 as i32,
                            ^~~~~~~~~~~~~
main_nope.rs:7:14: 7:27 error: constant evaluation error: non-constant path in constant expr [E0080]
main_nope.rs:7     Value2 = CEnum::Value2 as i32,
                            ^~~~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile `test`.

Caused by:
  Process didn't exit successfully: `rustc main_nope.rs --crate-name test --crate-type bin -g --out-dir C:\Users\LINK\De
sktop\rust-test\target\debug --emit=dep-info,link -L dependency=C:\Users\LINK\Desktop\rust-test\target\debug -L dependen
cy=C:\Users\LINK\Desktop\rust-test\target\debug\deps --extern excrate=C:\Users\LINK\Desktop\rust-test\target\debug\deps\
libexcrate-aed1a7b0d1e320a1.rlib` (exit code: 101)
PS C:\Users\LINK\Desktop\rust-test> rustc --version --verbose
rustc 1.0.0-beta (9854143cb 2015-04-02) (built 2015-04-02)
binary: rustc
commit-hash: 9854143cba679834bc4ef932858cd5303f015a0e
commit-date: 2015-04-02
build-date: 2015-04-02
host: i686-pc-windows-gnu
release: 1.0.0-beta
@ghost
Copy link

ghost commented Apr 15, 2015

Related (a dupe, really) to #24106.

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 20, 2015
@Manishearth
Copy link
Member

cc @oli-obk

@Mark-Simulacrum
Copy link
Member

No longer ICEs today. Regression test was added for #24106, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants