auto merge of #6204 : pcwalton/rust/uninhabited-enum-cast, r=catamorphism
r? @catamorphism
This commit is contained in:
commit
984180c600
@ -2499,12 +2499,15 @@ pub fn type_is_enum(ty: t) -> bool {
|
||||
// constructors
|
||||
pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
|
||||
match get(ty).sty {
|
||||
ty_enum(did, _) => {
|
||||
let variants = enum_variants(cx, did);
|
||||
let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
|
||||
return !some_n_ary;
|
||||
}
|
||||
_ => return false
|
||||
ty_enum(did, _) => {
|
||||
let variants = enum_variants(cx, did);
|
||||
if variants.len() == 0 {
|
||||
false
|
||||
} else {
|
||||
variants.all(|v| v.args.len() == 0)
|
||||
}
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
|
7
src/test/compile-fail/uninhabited-enum-cast.rs
Normal file
7
src/test/compile-fail/uninhabited-enum-cast.rs
Normal file
@ -0,0 +1,7 @@
|
||||
enum E {}
|
||||
|
||||
fn f(e: E) {
|
||||
println((e as int).to_str()); //~ ERROR non-scalar cast
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user