We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dc5df61 commit c0f587dCopy full SHA for c0f587d
src/librustc/middle/ty.rs
@@ -2509,12 +2509,15 @@ pub fn type_is_enum(ty: t) -> bool {
2509
// constructors
2510
pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
2511
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
+ ty_enum(did, _) => {
+ let variants = enum_variants(cx, did);
+ if variants.len() == 0 {
+ false
+ } else {
+ variants.all(|v| v.args.len() == 0)
2518
+ }
2519
2520
+ _ => false
2521
}
2522
2523
src/test/compile-fail/uninhabited-enum-cast.rs
@@ -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