Skip to content

Commit ab4105d

Browse files
committed
Make nonconstructable enums noncopyable, close #1907.
1 parent 0cf6b61 commit ab4105d

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/rustc/middle/ty.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1072,12 +1072,17 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
10721072
// Enums lower to the lowest of their variants.
10731073
ty_enum(did, tps) {
10741074
let mut lowest = kind_sendable;
1075-
for variant in *enum_variants(cx, did) {
1076-
for aty in variant.args {
1077-
// Perform any type parameter substitutions.
1078-
let arg_ty = substitute_type_params(cx, tps, aty);
1079-
lowest = lower_kind(lowest, type_kind(cx, arg_ty));
1080-
if lowest == kind_noncopyable { break; }
1075+
let variants = enum_variants(cx, did);
1076+
if vec::len(*variants) == 0u {
1077+
lowest = kind_noncopyable;
1078+
} else {
1079+
for variant in *variants {
1080+
for aty in variant.args {
1081+
// Perform any type parameter substitutions.
1082+
let arg_ty = substitute_type_params(cx, tps, aty);
1083+
lowest = lower_kind(lowest, type_kind(cx, arg_ty));
1084+
if lowest == kind_noncopyable { break; }
1085+
}
10811086
}
10821087
}
10831088
lowest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let x : *[int] = ptr::addr_of([1,2,3]);
3+
let y : *libc::c_void = x as *libc::c_void;
4+
unsafe {
5+
let _z = *y;
6+
//!^ ERROR copying a noncopyable value
7+
}
8+
}

0 commit comments

Comments
 (0)