Skip to content

Commit ee5d0f5

Browse files
committed
new test which features conflicting variance requirements
1 parent bd6e6e3 commit ee5d0f5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
fn main() {
2+
3+
// Note: here we do not have any type annotations
4+
// but we do express conflicting requirements:
5+
6+
let v = [mut [0]];
7+
let w = [mut [mut 0]];
8+
let x = [mut [mut 0]];
9+
10+
fn f(&&v: [mut [int]]) {
11+
v[0] = [3]
12+
}
13+
14+
fn g(&&v: [const [const int]]) {
15+
}
16+
17+
fn h(&&v: [mut [mut int]]) {
18+
v[0] = [mut 3]
19+
}
20+
21+
fn i(&&v: [mut [const int]]) {
22+
v[0] = [mut 3]
23+
}
24+
25+
fn j(&&v: [[const int]]) {
26+
}
27+
28+
f(v);
29+
g(v);
30+
h(v); //! ERROR (values differ in mutability)
31+
i(v); //! ERROR (values differ in mutability)
32+
j(v); //! ERROR (values differ in mutability)
33+
34+
f(w); //! ERROR (values differ in mutability)
35+
g(w);
36+
h(w);
37+
i(w); //! ERROR (values differ in mutability)
38+
j(w); //! ERROR (values differ in mutability)
39+
40+
// Note that without adding f() or h() to the mix, it is valid for
41+
// x to have the type [mut [const int]], and thus we can safely
42+
// call g() and i() but not j():
43+
g(x);
44+
i(x);
45+
j(x); //! ERROR (values differ in mutability)
46+
}

0 commit comments

Comments
 (0)