about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-10-18 10:35:33 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-18 10:37:04 -0700
commit314c011d71c699291361870e13892b4e5867d046 (patch)
treef0c57d6737e882e8511a4f51202e0060d52877ce /src/test
parent71a4a661359dbe92493f7321f8b3677dec734df9 (diff)
Immutable and mutable? are covariant on their inner types
Whereas [mutable T] is invariant with respect to T, [T] and [mutable? T]
are covariant with respect to T.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/mutable-huh-variance-vec1.rs13
-rw-r--r--src/test/run-pass/mutable-huh-variance-vec2.rs13
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/run-pass/mutable-huh-variance-vec1.rs b/src/test/run-pass/mutable-huh-variance-vec1.rs
new file mode 100644
index 00000000000..5fb49cf88ce
--- /dev/null
+++ b/src/test/run-pass/mutable-huh-variance-vec1.rs
@@ -0,0 +1,13 @@
+// error-pattern: mismatched types
+
+fn main() {
+    let v = [[0]];
+
+    // This is ok because the outer vec is covariant with respect
+    // to the inner vec. If the outer vec was mutable then we
+    // couldn't do this.
+    fn f(&&v: [[mutable? int]]) {
+    }
+
+    f(v);
+}
diff --git a/src/test/run-pass/mutable-huh-variance-vec2.rs b/src/test/run-pass/mutable-huh-variance-vec2.rs
new file mode 100644
index 00000000000..1e254e86806
--- /dev/null
+++ b/src/test/run-pass/mutable-huh-variance-vec2.rs
@@ -0,0 +1,13 @@
+// error-pattern: mismatched types
+
+fn main() {
+    let v = [[0]];
+
+    // This is ok because the outer vec is covariant with respect
+    // to the inner vec. If the outer vec was mutable then we
+    // couldn't do this.
+    fn f(&&v: [mutable? [mutable? int]]) {
+    }
+
+    f(v);
+}