From 0b2f2cabbe3fbe6e18cbf0f8a174b7d4789fc938 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 22 May 2012 14:10:32 -0700 Subject: Send is no longer a subkind of copy. This allows for sendable, but non-copyable resources. Closes #2420. --- src/rustc/middle/kind.rs | 10 ++++++---- src/rustc/middle/ty.rs | 12 ++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src/rustc/middle') diff --git a/src/rustc/middle/kind.rs b/src/rustc/middle/kind.rs index e7c318b7da5..effa593109c 100644 --- a/src/rustc/middle/kind.rs +++ b/src/rustc/middle/kind.rs @@ -24,10 +24,12 @@ import freevars::freevar_entry; // types. fn kind_to_str(k: kind) -> str { - if k == kind_sendable() { "sendable" } - else if k == kind_copyable() { "copyable" } - else if k == kind_noncopyable() { "noncopyable" } - else { fail "unknown kind" } + alt (ty::kind_can_be_copied(k), ty::kind_can_be_sent(k)) { + (false, false) { "noncopyable" } + (false, true) { "sendable" } + (true, false) { "copyable" } + (true, true) { "copy-sendable" } + } } type rval_map = std::map::hashmap; diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 998dc9d5951..52cee2fd07b 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -425,9 +425,9 @@ fn param_bounds_to_kind(bounds: param_bounds) -> kind { for vec::each(*bounds) {|bound| alt bound { bound_copy { - if kind != kind_sendable() { kind = kind_copyable(); } + kind = lower_kind(kind, kind_copyable()); } - bound_send { kind = kind_sendable(); } + bound_send { kind = lower_kind(kind, kind_send_only()); } _ {} } } @@ -1277,6 +1277,10 @@ fn kind_sendable() -> kind { kind_(KIND_MASK_COPY | KIND_MASK_SEND) } +fn kind_send_only() -> kind { + kind_(KIND_MASK_SEND) +} + // Using these query functons is preferable to direct comparison or matching // against the kind constants, as we may modify the kind hierarchy in the // future. @@ -1303,7 +1307,7 @@ fn kind_lteq(a: kind, b: kind) -> bool { } fn lower_kind(a: kind, b: kind) -> kind { - if kind_lteq(a, b) { a } else { b } + kind_(*a | *b) } #[test] @@ -1402,7 +1406,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind { } lowest } - ty_res(did, inner, tps) { kind_noncopyable() } + ty_res(did, inner, tps) { kind_send_only() } ty_param(_, did) { param_bounds_to_kind(cx.ty_param_bounds.get(did.node)) } -- cgit 1.4.1-3-g733a5