Skip to content

ICE on with #[repr(..)] for single-variant enum #34571

New issue

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

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

Already on GitHub? # to your account

Closed
Ericson2314 opened this issue Jun 30, 2016 · 8 comments
Closed

ICE on with #[repr(..)] for single-variant enum #34571

Ericson2314 opened this issue Jun 30, 2016 · 8 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Ericson2314
Copy link
Contributor

#[repr(u8)]
enum Foo {
    Foo(u8),
}

fn main() {
    match Foo::Foo(1) {
        _ => ()
    }
}

Same error on all nightly and stable:

error: internal compiler error: unexpected panic
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 'assertion failed: `(left == right)` (left: `ReprInt(<anon>:1:8: 1:10, UnsignedInt(u8))`, right: `ReprAny`)', ../src/librustc/ty/layout.rs:953
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 30, 2016
@nagisa
Copy link
Member

nagisa commented Jun 30, 2016

cc @eddyb

@eddyb
Copy link
Member

eddyb commented Jun 30, 2016

How does this not trigger an error?

@TimNN
Copy link
Contributor

TimNN commented Jul 15, 2016

Note that adding a second variant reports no error at all (I stumbled upon this ICE as well, just now):

#[repr(u8)]
enum Foo {
    Foo(u8),
    Bar
}

Edit: this is already tracked at #31692

@TimNN
Copy link
Contributor

TimNN commented Jul 15, 2016

Probably relevant from #25651:

the #[repr] attribute on data-carrying enums is intentional (e.g. to control the size of the discriminant. It's just quite rare that it's actually used.

@TimNN
Copy link
Contributor

TimNN commented Jul 17, 2016

This has become a regression (probably since #34846 was merged):

The following compiles fine on stable, beta and nightly-2016-07-12 but fails on later nightlies.

#[repr(C)]
pub enum TupleSingle {
     Tuple(u8),
}

fn main() {}

@jonas-schievink
Copy link
Contributor

Interestingly, it's only a regression if the enum was completely unused before. @eddyb's type layout code will be invoked for all types that are lowered down to an LLVM representation, which doesn't happen if the type is unused. This ICEs on stable, too:

#[repr(u8)]
pub enum TupleSingle {
    Tuple(u8),
}

fn main() {
    let t = TupleSingle::Tuple(0);
}

@zackmdavis
Copy link
Member

Doesn't seem to reproduce anymore?

$ rustc --version
rustc 1.14.0-nightly (a3bc191b5 2016-10-10)
$ cat scratch.rs 
#[repr(u8)]
enum Foo {
    Foo(u8),
}

fn main() {
    match Foo::Foo(1) {
        _ => ()
    }
}
$ rustc scratch.rs 
$ echo $?
0

@TimNN
Copy link
Contributor

TimNN commented Oct 16, 2016

This was fixed between nightly-2016-09-22 and nightly-2016-09-27 (Changes), more precisely this was fixed by #36151, as far as I can tell.

I'm gonna tag this as needstest so we can make sure this does not regress in future.

@TimNN TimNN added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 16, 2016
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 17, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 17, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 18, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 19, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 19, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

7 participants