Skip to content

Commit 6e2aa3b

Browse files
committed
Port more resource tests to classes
1 parent 14e3fde commit 6e2aa3b

File tree

8 files changed

+38
-22
lines changed

8 files changed

+38
-22
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// test that autoderef of a type like this does not
22
// cause compiler to loop. Note that no instances
33
// of such a type could ever be constructed.
4-
resource t(x: x) {} //! ERROR this type cannot be instantiated
5-
enum x = @t; //! ERROR this type cannot be instantiated
6-
7-
fn new_t(x: t) {
8-
x.to_str; //! ERROR attempted access of field to_str
4+
class t { //! ERROR this type cannot be instantiated
5+
let x: x;
6+
let to_str: ();
7+
new(x: x) { self.x = x; self.to_str = (); }
98
}
9+
enum x = @t; //! ERROR this type cannot be instantiated
1010
1111
fn main() {
1212
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22

33
fn foo<T: const>(_x: T) { }
44

5-
resource r(_x: int) {}
6-
resource r2(_x: @mut int) {}
5+
class r {
6+
let x:int;
7+
new(x:int) { self.x = x; }
8+
drop {}
9+
}
10+
11+
class r2 {
12+
let x:@mut int;
13+
new(x:@mut int) { self.x = x; }
14+
drop {}
15+
}
716

817
fn main() {
918
foo({f: 3});

src/test/compile-fail/pinned-deep-copy.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// error-pattern: copying a noncopyable value
22

3-
resource r(i: @mut int) {
4-
*i = *i + 1;
3+
class r {
4+
let i: @mut int;
5+
new(i: @mut int) { self.i = i; }
6+
drop { *(self.i) = *(self.i) + 1; }
57
}
68

79
fn main() {

src/test/compile-fail/record-with-resource.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// error-pattern: copying a noncopyable value
22

3-
resource my_resource(x: int) {
4-
log(error, x);
3+
class my_resource {
4+
let x: int;
5+
new(x: int) { self.x = x; }
6+
drop { log(error, self.x); }
57
}
68

79
fn main() {

src/test/compile-fail/regions-bounds.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
enum an_enum/& { }
66
iface an_iface/& { }
77
class a_class/& { new() { } }
8-
resource a_rsrc/&(_x: ()) { }
98

109
fn a_fn1(e: an_enum/&a) -> an_enum/&b {
1110
ret e; //! ERROR mismatched types: expected `an_enum/&b` but found `an_enum/&a`
@@ -19,11 +18,7 @@ fn a_fn3(e: a_class/&a) -> a_class/&b {
1918
ret e; //! ERROR mismatched types: expected `a_class/&b` but found `a_class/&a`
2019
}
2120

22-
fn a_fn4(e: a_rsrc/&a) -> a_rsrc/&b {
23-
ret e; //! ERROR mismatched types: expected `a_rsrc/&b` but found `a_rsrc/&a`
24-
}
25-
26-
fn a_fn5(e: int/&a) -> int/&b {
21+
fn a_fn4(e: int/&a) -> int/&b {
2722
//!^ ERROR Region parameters are not allowed on this type.
2823
//!^^ ERROR Region parameters are not allowed on this type.
2924
ret e;

src/test/compile-fail/unique-pinned-nocopy.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// error-pattern: copying a noncopyable value
22

3-
resource r(b: bool) {
3+
class r {
4+
let b:bool;
5+
new(b: bool) { self.b = b; }
6+
drop {}
47
}
58

69
fn main() {

src/test/compile-fail/unique-vec-res.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// error-pattern: copying a noncopyable value
22

3-
resource r(i: @mut int) {
4-
*i = *i + 1;
3+
class r {
4+
let i: @mut int;
5+
new(i: @mut int) { self.i = i; }
6+
drop { *(self.i) = *(self.i) + 1; }
57
}
68

79
fn f<T>(+i: [T], +j: [T]) {

src/test/compile-fail/vec-res-add.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// error-pattern: copying a noncopyable value
22

3-
resource r(_i: int) { }
3+
class r {
4+
new(_i:int) {}
5+
drop {}
6+
}
47

58
fn main() {
6-
// This can't make sense as it would copy the resources
9+
// This can't make sense as it would copy the classes
710
let i <- [r(0)];
811
let j <- [r(1)];
912
let k = i + j;

0 commit comments

Comments
 (0)