auto merge of #6204 : pcwalton/rust/uninhabited-enum-cast, r=catamorphism

r? @catamorphism
This commit is contained in:
bors 2013-05-03 00:12:37 -07:00
commit 984180c600
2 changed files with 16 additions and 6 deletions

View File

@ -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
}
}

View File

@ -0,0 +1,7 @@
enum E {}
fn f(e: E) {
println((e as int).to_str()); //~ ERROR non-scalar cast
}
fn main() {}