Skip to content

Commit 984180c

Browse files
committed
auto merge of #6204 : pcwalton/rust/uninhabited-enum-cast, r=catamorphism
r? @catamorphism
2 parents 2ae44a0 + c0f587d commit 984180c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/librustc/middle/ty.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,12 +2499,15 @@ pub fn type_is_enum(ty: t) -> bool {
24992499
// constructors
25002500
pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
25012501
match get(ty).sty {
2502-
ty_enum(did, _) => {
2503-
let variants = enum_variants(cx, did);
2504-
let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
2505-
return !some_n_ary;
2506-
}
2507-
_ => return false
2502+
ty_enum(did, _) => {
2503+
let variants = enum_variants(cx, did);
2504+
if variants.len() == 0 {
2505+
false
2506+
} else {
2507+
variants.all(|v| v.args.len() == 0)
2508+
}
2509+
}
2510+
_ => false
25082511
}
25092512
}
25102513
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum E {}
2+
3+
fn f(e: E) {
4+
println((e as int).to_str()); //~ ERROR non-scalar cast
5+
}
6+
7+
fn main() {}

0 commit comments

Comments
 (0)