Make nonconstructable enums noncopyable, close #1907.
This commit is contained in:
parent
0cf6b613d1
commit
ab4105d9e8
@ -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
|
||||
|
8
src/test/compile-fail/non-copyable-void.rs
Normal file
8
src/test/compile-fail/non-copyable-void.rs
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user