about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-05-03 16:26:43 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-05-03 16:27:16 -0400
commitbe08c3e5146953619ff777aaa422152dfee4ad28 (patch)
tree0dd6cad23983eaea96cf6718e3fa6d672e077469 /src/test
parentf3a6ea26437e240b02d749331b3a2d60aab0588b (diff)
rustc: add rooting, write-guards to slices etc
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-fail/borrowck-wg-fail-2.rs3
-rw-r--r--src/test/run-fail/borrowck-wg-fail-3.rs3
-rw-r--r--src/test/run-fail/borrowck-wg-fail.rs3
-rw-r--r--src/test/run-fail/borrowck-wg-one-mut-one-imm-slice-method.rs37
-rw-r--r--src/test/run-fail/borrowck-wg-one-mut-one-imm-slices.rs16
-rw-r--r--src/test/run-fail/borrowck-wg-one-mut-one-imm.rs17
-rw-r--r--src/test/run-fail/borrowck-wg-two-array-indices.rs17
-rw-r--r--src/test/run-pass/borrowck-wg-two-imm-borrows.rs14
8 files changed, 110 insertions, 0 deletions
diff --git a/src/test/run-fail/borrowck-wg-fail-2.rs b/src/test/run-fail/borrowck-wg-fail-2.rs
index 121ec9c7921..59a5fecd340 100644
--- a/src/test/run-fail/borrowck-wg-fail-2.rs
+++ b/src/test/run-fail/borrowck-wg-fail-2.rs
@@ -1,5 +1,8 @@
 // error-pattern:borrowed
 
+// Test that write guards trigger when there is a write to a field
+// of a frozen structure.
+
 struct S {
     x: int
 }
diff --git a/src/test/run-fail/borrowck-wg-fail-3.rs b/src/test/run-fail/borrowck-wg-fail-3.rs
index 2b95cf3fe5f..ebff553aafb 100644
--- a/src/test/run-fail/borrowck-wg-fail-3.rs
+++ b/src/test/run-fail/borrowck-wg-fail-3.rs
@@ -1,5 +1,8 @@
 // error-pattern:borrowed
 
+// Test that write guards trigger when there is a write to a directly
+// frozen @mut box.
+
 fn main() {
     let x = @mut 3;
     let y: &mut int = x;
diff --git a/src/test/run-fail/borrowck-wg-fail.rs b/src/test/run-fail/borrowck-wg-fail.rs
index fd2d36b895a..939d802c21c 100644
--- a/src/test/run-fail/borrowck-wg-fail.rs
+++ b/src/test/run-fail/borrowck-wg-fail.rs
@@ -1,5 +1,8 @@
 // error-pattern:borrowed
 
+// Test that write guards trigger when mut box is frozen
+// as part of argument coercion.
+
 fn f(_x: &int, y: @mut int) {
     *y = 2;
 }
diff --git a/src/test/run-fail/borrowck-wg-one-mut-one-imm-slice-method.rs b/src/test/run-fail/borrowck-wg-one-mut-one-imm-slice-method.rs
new file mode 100644
index 00000000000..91df90f8b3a
--- /dev/null
+++ b/src/test/run-fail/borrowck-wg-one-mut-one-imm-slice-method.rs
@@ -0,0 +1,37 @@
+// error-pattern:borrowed
+
+// Test that write guards trigger when there is a coercion to
+// a slice on the receiver of a method.
+
+trait MyMutSlice {
+    fn my_mut_slice(self) -> Self;
+}
+
+impl<'self, T> MyMutSlice for &'self mut [T] {
+    fn my_mut_slice(self) -> &'self mut [T] {
+        self
+    }
+}
+
+trait MySlice {
+    fn my_slice(self) -> Self;
+}
+
+impl<'self, T> MySlice for &'self [T] {
+    fn my_slice(self) -> &'self [T] {
+        self
+    }
+}
+
+fn add(x:&mut [int], y:&[int])
+{
+    x[0] = x[0] + y[0];
+}
+
+pub fn main()
+{
+    let z = @mut [1,2,3];
+    let z2 = z;
+    add(z.my_mut_slice(), z2.my_slice());
+    print(fmt!("%d\n", z[0]));
+}
diff --git a/src/test/run-fail/borrowck-wg-one-mut-one-imm-slices.rs b/src/test/run-fail/borrowck-wg-one-mut-one-imm-slices.rs
new file mode 100644
index 00000000000..bae693ce4ea
--- /dev/null
+++ b/src/test/run-fail/borrowck-wg-one-mut-one-imm-slices.rs
@@ -0,0 +1,16 @@
+// error-pattern:borrowed
+
+// Test that write guards trigger when arguments are coerced to slices.
+
+fn add(x:&mut [int], y:&[int])
+{
+    x[0] = x[0] + y[0];
+}
+
+pub fn main()
+{
+    let z = @mut [1,2,3];
+    let z2 = z;
+    add(z, z2);
+    print(fmt!("%d\n", z[0]));
+}
diff --git a/src/test/run-fail/borrowck-wg-one-mut-one-imm.rs b/src/test/run-fail/borrowck-wg-one-mut-one-imm.rs
new file mode 100644
index 00000000000..9e2a02b32df
--- /dev/null
+++ b/src/test/run-fail/borrowck-wg-one-mut-one-imm.rs
@@ -0,0 +1,17 @@
+// error-pattern:borrowed
+
+// Test that write guards trigger when we are indexing into
+// an @mut vector.
+
+fn add(x:&mut int, y:&int)
+{
+    *x = *x + *y;
+}
+
+pub fn main()
+{
+    let z = @mut [1,2,3];
+    let z2 = z;
+    add(&mut z[0], &z2[0]);
+    print(fmt!("%d\n", z[0]));
+}
diff --git a/src/test/run-fail/borrowck-wg-two-array-indices.rs b/src/test/run-fail/borrowck-wg-two-array-indices.rs
new file mode 100644
index 00000000000..ad684488760
--- /dev/null
+++ b/src/test/run-fail/borrowck-wg-two-array-indices.rs
@@ -0,0 +1,17 @@
+// error-pattern:borrowed
+
+// Test that arguments trigger when there are *two mutable* borrows
+// of indices.
+
+fn add(x:&mut int, y:&mut int)
+{
+    *x = *x + *y;
+}
+
+pub fn main()
+{
+    let z = @mut [1,2,3];
+    let z2 = z;
+    add(&mut z[0], &mut z2[0]);
+    print(fmt!("%d\n", z[0]));
+}
diff --git a/src/test/run-pass/borrowck-wg-two-imm-borrows.rs b/src/test/run-pass/borrowck-wg-two-imm-borrows.rs
new file mode 100644
index 00000000000..20f824e969a
--- /dev/null
+++ b/src/test/run-pass/borrowck-wg-two-imm-borrows.rs
@@ -0,0 +1,14 @@
+// Test that we can borrow the same @mut box twice, so long as both are imm.
+
+fn add(x:&int, y:&int)
+{
+    *x + *y;
+}
+
+pub fn main()
+{
+    let z = @mut [1,2,3];
+    let z2 = z;
+    add(&z[0], &z2[0]);
+    print(fmt!("%d\n", z[0]));
+}