From ee5d0f5e3f1681a67452b5301958474343b90c51 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 24 Mar 2012 10:14:03 -0700 Subject: [PATCH] new test which features conflicting variance requirements --- .../compile-fail/mutable-huh-variance-vec4.rs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/compile-fail/mutable-huh-variance-vec4.rs diff --git a/src/test/compile-fail/mutable-huh-variance-vec4.rs b/src/test/compile-fail/mutable-huh-variance-vec4.rs new file mode 100644 index 00000000000..74b6ad9ff62 --- /dev/null +++ b/src/test/compile-fail/mutable-huh-variance-vec4.rs @@ -0,0 +1,46 @@ +fn main() { + + // Note: here we do not have any type annotations + // but we do express conflicting requirements: + + let v = [mut [0]]; + let w = [mut [mut 0]]; + let x = [mut [mut 0]]; + + fn f(&&v: [mut [int]]) { + v[0] = [3] + } + + fn g(&&v: [const [const int]]) { + } + + fn h(&&v: [mut [mut int]]) { + v[0] = [mut 3] + } + + fn i(&&v: [mut [const int]]) { + v[0] = [mut 3] + } + + fn j(&&v: [[const int]]) { + } + + f(v); + g(v); + h(v); //! ERROR (values differ in mutability) + i(v); //! ERROR (values differ in mutability) + j(v); //! ERROR (values differ in mutability) + + f(w); //! ERROR (values differ in mutability) + g(w); + h(w); + i(w); //! ERROR (values differ in mutability) + j(w); //! ERROR (values differ in mutability) + + // Note that without adding f() or h() to the mix, it is valid for + // x to have the type [mut [const int]], and thus we can safely + // call g() and i() but not j(): + g(x); + i(x); + j(x); //! ERROR (values differ in mutability) +}