Skip to content

Commit d174d91

Browse files
committed
Calculate the correct kind for unique boxes
Issue #409
1 parent 61a14f3 commit d174d91

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

src/comp/middle/ty.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,9 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10191019
ty_box(mt) {
10201020
result = ast::kind_shared;
10211021
}
1022-
ty_uniq(mt) {
1023-
// FIXME (409): Calculate kind
1024-
result = ast::kind_unique;
1025-
}
10261022
// Pointers and unique boxes / vecs raise pinned to shared,
10271023
// otherwise pass through their pointee kind.
1028-
ty_ptr(tm) | ty_vec(tm) {
1024+
ty_ptr(tm) | ty_vec(tm) | ty_uniq(tm) {
10291025
let k = type_kind(cx, tm.ty);
10301026
if k == ast::kind_pinned { k = ast::kind_shared; }
10311027
result = kind::lower_kind(result, k);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// error-pattern: needed unique type
2+
3+
fn f<~T>(i: T) {
4+
}
5+
6+
fn main() {
7+
let i = ~@100;
8+
f(i);
9+
}

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
fn unique() {
2+
3+
fn f<~T>(i: T, j: T) {
4+
assert i == j;
5+
}
6+
7+
fn g<~T>(i: T, j: T) {
8+
assert i != j;
9+
}
10+
11+
let i = ~100;
12+
let j = ~100;
13+
f(i, j);
14+
let i = ~100;
15+
let j = ~101;
16+
g(i, j);
17+
}
18+
19+
fn shared() {
20+
21+
fn f<@T>(i: T, j: T) {
22+
assert i == j;
23+
}
24+
25+
fn g<@T>(i: T, j: T) {
26+
assert i != j;
27+
}
28+
29+
let i = ~100;
30+
let j = ~100;
31+
f(i, j);
32+
let i = ~100;
33+
let j = ~101;
34+
g(i, j);
35+
}
36+
37+
fn pinned() {
38+
39+
fn f<T>(i: T, j: T) {
40+
assert i == j;
41+
}
42+
43+
fn g<T>(i: T, j: T) {
44+
assert i != j;
45+
}
46+
47+
let i = ~100;
48+
let j = ~100;
49+
f(i, j);
50+
let i = ~100;
51+
let j = ~101;
52+
g(i, j);
53+
}
54+
55+
fn main() {
56+
unique();
57+
shared();
58+
pinned();
59+
}

0 commit comments

Comments
 (0)