Calculate the correct kind for unique boxes

Issue #409
This commit is contained in:
Brian Anderson 2011-09-22 15:28:49 -07:00
parent 61a14f3df0
commit d174d917e2
3 changed files with 69 additions and 5 deletions

View File

@ -1019,13 +1019,9 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
ty_box(mt) {
result = ast::kind_shared;
}
ty_uniq(mt) {
// FIXME (409): Calculate kind
result = ast::kind_unique;
}
// Pointers and unique boxes / vecs raise pinned to shared,
// otherwise pass through their pointee kind.
ty_ptr(tm) | ty_vec(tm) {
ty_ptr(tm) | ty_vec(tm) | ty_uniq(tm) {
let k = type_kind(cx, tm.ty);
if k == ast::kind_pinned { k = ast::kind_shared; }
result = kind::lower_kind(result, k);

View File

@ -0,0 +1,9 @@
// error-pattern: needed unique type
fn f<~T>(i: T) {
}
fn main() {
let i = ~@100;
f(i);
}

View File

@ -0,0 +1,59 @@
fn unique() {
fn f<~T>(i: T, j: T) {
assert i == j;
}
fn g<~T>(i: T, j: T) {
assert i != j;
}
let i = ~100;
let j = ~100;
f(i, j);
let i = ~100;
let j = ~101;
g(i, j);
}
fn shared() {
fn f<@T>(i: T, j: T) {
assert i == j;
}
fn g<@T>(i: T, j: T) {
assert i != j;
}
let i = ~100;
let j = ~100;
f(i, j);
let i = ~100;
let j = ~101;
g(i, j);
}
fn pinned() {
fn f<T>(i: T, j: T) {
assert i == j;
}
fn g<T>(i: T, j: T) {
assert i != j;
}
let i = ~100;
let j = ~100;
f(i, j);
let i = ~100;
let j = ~101;
g(i, j);
}
fn main() {
unique();
shared();
pinned();
}