Unique pointers containing pinned kinds become pinned

Issue #409
This commit is contained in:
Brian Anderson 2011-09-23 18:13:49 -07:00
parent 97629727b1
commit e5d5682065
4 changed files with 25 additions and 4 deletions

View File

@ -1021,11 +1021,18 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
}
// Pointers and unique boxes / vecs raise pinned to shared,
// otherwise pass through their pointee kind.
ty_ptr(tm) | ty_vec(tm) | ty_uniq(tm) {
ty_ptr(tm) | ty_vec(tm) {
let k = type_kind(cx, tm.ty);
if k == ast::kind_pinned { k = ast::kind_shared; }
result = kind::lower_kind(result, k);
}
// Unique boxes pass through their pointee kind. FIXME: Shouldn't
// pointers and vecs do this too to avoid copying vectors of pinned
// things?
ty_uniq(tm) {
let k = type_kind(cx, tm.ty);
result = kind::lower_kind(result, k);
}
// Records lower to the lowest of their members.
ty_rec(flds) {
for f: field in flds {

View File

@ -0,0 +1,10 @@
// error-pattern: mismatched kind
resource r(b: bool) {
}
fn main() {
let i = ~r(true);
let j;
j = i;
}

View File

@ -1,8 +1,6 @@
type recbox<T> = {x: ~T};
fn reclift<T>(t: T) -> recbox<T> { ret {x: ~t}; }
fn reclift<@T>(t: T) -> recbox<T> { ret {x: ~t}; }
fn main() {
let foo: int = 17;

View File

@ -1,3 +1,9 @@
// xfail-test
// This no longer works because ~r() is lowered to a pinned type
// (which can't be swapped). Should probably be a compile-fail
// test.
resource r(i: @mutable int) {
*i += 1;
}