blob: e0980826a2a599f2057fa387559524c238354bf2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
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)
}
|