Skip to content

Commit de40318

Browse files
committed
Tests for copyability and sendability rules for classes
Closes #2296
1 parent 11b4a92 commit de40318

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// error-pattern: copying a noncopyable value
2+
3+
// Test that a class with a non-copyable field can't be
4+
// copied
5+
class bar {
6+
new() {}
7+
drop {}
8+
}
9+
10+
class foo {
11+
let i: int;
12+
let j: bar;
13+
new(i:int) { self.i = i; self.j = bar(); }
14+
}
15+
16+
fn main() { let x <- foo(10); let y = x; log(error, x); }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Test that a class with an unsendable field can't be
2+
// sent
3+
4+
class foo {
5+
let i: int;
6+
let j: @str;
7+
new(i:int, j: @str) { self.i = i; self.j = j; }
8+
}
9+
10+
fn main() {
11+
let cat = "kitty";
12+
let po = comm::port(); //! ERROR missing `send`
13+
let ch = comm::chan(po); //! ERROR missing `send`
14+
comm::send(ch, foo(42, @cat)); //! ERROR missing `send`
15+
}

src/test/run-pass/sendable-class.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test that a class with only sendable fields can be sent
2+
3+
class foo {
4+
let i: int;
5+
let j: char;
6+
new(i:int, j: char) { self.i = i; self.j = j; }
7+
}
8+
9+
fn main() {
10+
let po = comm::port::<foo>();
11+
let ch = comm::chan(po);
12+
comm::send(ch, foo(42, 'c'));
13+
}

0 commit comments

Comments
 (0)