Skip to content

Commit c0f587d

Browse files
committed
librustc: Make uninhabited enums not castable to int
1 parent dc5df61 commit c0f587d

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/librustc/middle/ty.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -2509,12 +2509,15 @@ pub fn type_is_enum(ty: t) -> bool {
25092509
// constructors
25102510
pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
25112511
match get(ty).sty {
2512-
ty_enum(did, _) => {
2513-
let variants = enum_variants(cx, did);
2514-
let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
2515-
return !some_n_ary;
2516-
}
2517-
_ => return false
2512+
ty_enum(did, _) => {
2513+
let variants = enum_variants(cx, did);
2514+
if variants.len() == 0 {
2515+
false
2516+
} else {
2517+
variants.all(|v| v.args.len() == 0)
2518+
}
2519+
}
2520+
_ => false
25182521
}
25192522
}
25202523
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)