diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index b30db401da5..8ab1330fad9 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -1072,12 +1072,17 @@ fn type_kind(cx: ctxt, ty: t) -> kind { // Enums lower to the lowest of their variants. ty_enum(did, tps) { let mut lowest = kind_sendable; - for variant in *enum_variants(cx, did) { - for aty in variant.args { - // Perform any type parameter substitutions. - let arg_ty = substitute_type_params(cx, tps, aty); - lowest = lower_kind(lowest, type_kind(cx, arg_ty)); - if lowest == kind_noncopyable { break; } + let variants = enum_variants(cx, did); + if vec::len(*variants) == 0u { + lowest = kind_noncopyable; + } else { + for variant in *variants { + for aty in variant.args { + // Perform any type parameter substitutions. + let arg_ty = substitute_type_params(cx, tps, aty); + lowest = lower_kind(lowest, type_kind(cx, arg_ty)); + if lowest == kind_noncopyable { break; } + } } } lowest diff --git a/src/test/compile-fail/non-copyable-void.rs b/src/test/compile-fail/non-copyable-void.rs new file mode 100644 index 00000000000..91a625b05d0 --- /dev/null +++ b/src/test/compile-fail/non-copyable-void.rs @@ -0,0 +1,8 @@ +fn main() { + let x : *[int] = ptr::addr_of([1,2,3]); + let y : *libc::c_void = x as *libc::c_void; + unsafe { + let _z = *y; + //!^ ERROR copying a noncopyable value + } +}