rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.16k stars 12.8k forks source link

ICE when accessing value on a enum variant #38939

Closed bombless closed 7 years ago

bombless commented 7 years ago
#![feature(associated_consts)]

trait Foo {
    const X: u8 = 42;
    fn test();
}

enum Bar {
    X
}

impl Foo for Bar {
    fn test() {
        println!("{}", Self::X);
    }
}

fn main() {
    Bar::X::test();
}

https://is.gd/uL2NUM

rustc 1.16.0-nightly (7e38a89a7 2017-01-06)
error: internal compiler error: /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1516: unexpected definition: Variant(DefId { krate: CrateNum(0), node: DefIndex(8) => rust_out/4089d7c8b778d88cec885baf7b69e6df-exe::Bar[0]::X[0] })
  (B--> <anon>:19:5(B
   (B|
19 (B|     Bar::X::test();(B
   (B|     (B^^^^^^^^^^^^

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

thread 'rustc' panicked at 'Box<Any>', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_errors/lib.rs:382
note: Run with `RUST_BACKTRACE=1` for a backtrace.
bombless commented 7 years ago

Seems that the real issue is about accessing a value on a enum variant.

enum Bar {
    X
}

fn main() {
    Bar::X::test;
}

The ICE is only triggered on nightly, no feature-gate required.

petrochenkov commented 7 years ago

Duplicate of https://github.com/rust-lang/rust/issues/38862, fixed in https://github.com/rust-lang/rust/pull/38925