Skip to content

Commit

Permalink
auto merge of #6204 : pcwalton/rust/uninhabited-enum-cast, r=catamorp…
Browse files Browse the repository at this point in the history
…hism

r? @catamorphism
  • Loading branch information
bors committed May 3, 2013
2 parents 2ae44a0 + c0f587d commit 984180c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/compile-fail/uninhabited-enum-cast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum E {}

fn f(e: E) {
println((e as int).to_str()); //~ ERROR non-scalar cast
}

fn main() {}

0 comments on commit 984180c

Please sign in to comment.