Skip to content

Commit 0470abe

Browse files
committed
Allow some resources to be considered const.
1 parent 3acc3c4 commit 0470abe

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/rustc/middle/ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,10 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
15261526
}
15271527
lowest
15281528
}
1529-
ty_res(did, inner, tps) { kind_send_only() }
1529+
ty_res(did, inner, tps) {
1530+
let inner = subst(cx, tps, inner);
1531+
(kind_const() & type_kind(cx, inner)) | kind_send_only()
1532+
}
15301533
ty_param(_, did) {
15311534
// FIXME: type params shouldn't be implicitly copyable (#2449)
15321535
let k = param_bounds_to_kind(cx.ty_param_bounds.get(did.node));

src/test/compile-fail/non-const.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
fn foo<T: const>(_x: T) { }
44

55
resource r(_x: int) {}
6+
resource r2(_x: @mut int) {}
67

78
fn main() {
89
foo({f: 3});
@@ -13,7 +14,8 @@ fn main() {
1314
foo(~mut 1); //! ERROR missing `const`
1415
foo(@1);
1516
foo(@mut 1); //! ERROR missing `const`
16-
foo(r(1)); //! ERROR missing `const`
17+
foo(r(1)); // this is okay now.
18+
foo(r2(@mut 1)); //! ERROR missing `const`
1719
foo("123");
1820
foo({f: {mut f: 1}}); //! ERROR missing `const`
1921
}

0 commit comments

Comments
 (0)