From e5d5682065eac04322bb1cc21c1cd672393c6c33 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 23 Sep 2011 18:13:49 -0700 Subject: [PATCH] Unique pointers containing pinned kinds become pinned Issue #409 --- src/comp/middle/ty.rs | 9 ++++++++- src/test/compile-fail/unique-pinned-nocopy.rs | 10 ++++++++++ src/test/run-pass/generic-exterior-unique.rs | 4 +--- src/test/run-pass/unique-swap2.rs | 6 ++++++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/test/compile-fail/unique-pinned-nocopy.rs diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index c48e3fe03dc..190b974f72a 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -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 { diff --git a/src/test/compile-fail/unique-pinned-nocopy.rs b/src/test/compile-fail/unique-pinned-nocopy.rs new file mode 100644 index 00000000000..9c1cad78b03 --- /dev/null +++ b/src/test/compile-fail/unique-pinned-nocopy.rs @@ -0,0 +1,10 @@ +// error-pattern: mismatched kind + +resource r(b: bool) { +} + +fn main() { + let i = ~r(true); + let j; + j = i; +} \ No newline at end of file diff --git a/src/test/run-pass/generic-exterior-unique.rs b/src/test/run-pass/generic-exterior-unique.rs index a7eb0b8bdac..16f9f3aec67 100644 --- a/src/test/run-pass/generic-exterior-unique.rs +++ b/src/test/run-pass/generic-exterior-unique.rs @@ -1,8 +1,6 @@ - - type recbox = {x: ~T}; -fn reclift(t: T) -> recbox { ret {x: ~t}; } +fn reclift<@T>(t: T) -> recbox { ret {x: ~t}; } fn main() { let foo: int = 17; diff --git a/src/test/run-pass/unique-swap2.rs b/src/test/run-pass/unique-swap2.rs index 027958115fd..041ac622c91 100644 --- a/src/test/run-pass/unique-swap2.rs +++ b/src/test/run-pass/unique-swap2.rs @@ -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; }