Skip to content

Commit e5d5682

Browse files
committed
Unique pointers containing pinned kinds become pinned
Issue #409
1 parent 9762972 commit e5d5682

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/comp/middle/ty.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1021,11 +1021,18 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10211021
}
10221022
// Pointers and unique boxes / vecs raise pinned to shared,
10231023
// otherwise pass through their pointee kind.
1024-
ty_ptr(tm) | ty_vec(tm) | ty_uniq(tm) {
1024+
ty_ptr(tm) | ty_vec(tm) {
10251025
let k = type_kind(cx, tm.ty);
10261026
if k == ast::kind_pinned { k = ast::kind_shared; }
10271027
result = kind::lower_kind(result, k);
10281028
}
1029+
// Unique boxes pass through their pointee kind. FIXME: Shouldn't
1030+
// pointers and vecs do this too to avoid copying vectors of pinned
1031+
// things?
1032+
ty_uniq(tm) {
1033+
let k = type_kind(cx, tm.ty);
1034+
result = kind::lower_kind(result, k);
1035+
}
10291036
// Records lower to the lowest of their members.
10301037
ty_rec(flds) {
10311038
for f: field in flds {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// error-pattern: mismatched kind
2+
3+
resource r(b: bool) {
4+
}
5+
6+
fn main() {
7+
let i = ~r(true);
8+
let j;
9+
j = i;
10+
}

src/test/run-pass/generic-exterior-unique.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
2-
31
type recbox<T> = {x: ~T};
42

5-
fn reclift<T>(t: T) -> recbox<T> { ret {x: ~t}; }
3+
fn reclift<@T>(t: T) -> recbox<T> { ret {x: ~t}; }
64

75
fn main() {
86
let foo: int = 17;

src/test/run-pass/unique-swap2.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// xfail-test
2+
3+
// This no longer works because ~r() is lowered to a pinned type
4+
// (which can't be swapped). Should probably be a compile-fail
5+
// test.
6+
17
resource r(i: @mutable int) {
28
*i += 1;
39
}

0 commit comments

Comments
 (0)