Make nonconstructable enums noncopyable, close #1907.

This commit is contained in:
Graydon Hoare 2012-04-04 19:07:52 -07:00
parent 0cf6b613d1
commit ab4105d9e8
2 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -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
}
}