rust icon indicating copy to clipboard operation
rust copied to clipboard

Crash with C-style enums

Open DoctorAlpaca opened this issue 13 years ago • 5 comments

This snippet crashes the compiler:

enum foo {
    a = 1,
    b = 2,
    c = a | b
}

With this error:

$ rustc bug.rs 
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues

Using an expression that I'd actually expect to work (like c = a as int | b as int) also yields a suspicious looking message:

error: internal compiler error: node_id_to_type: no type for node `expr a as int (id=11)`

DoctorAlpaca avatar May 14 '13 14:05 DoctorAlpaca

Nominating for well-defined.

jdm avatar May 14 '13 15:05 jdm

just a bug, removing milestone/nomination.

graydon avatar May 16 '13 16:05 graydon

accepted for production-ready milestone

graydon avatar May 16 '13 16:05 graydon

The latter form (with the casts) still ICEs. The former form now gives a more pleasant error:

t.rs:4:8: 4:13 error: Bad operands for binary
t.rs:4     c = a | b
               ^~~~~

But still doesn't compile.

graydon avatar Jul 25 '13 07:07 graydon

This works if you cast the variants first, which is expected.

Closing.

Aatch avatar Mar 04 '14 02:03 Aatch