2012-12-10 19:32:48 -06:00
|
|
|
// 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.
|
|
|
|
|
2012-03-24 12:14:03 -05:00
|
|
|
fn main() {
|
|
|
|
|
|
|
|
// Note: here we do not have any type annotations
|
|
|
|
// but we do express conflicting requirements:
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let v = ~[mut ~[0]];
|
|
|
|
let w = ~[mut ~[mut 0]];
|
|
|
|
let x = ~[mut ~[mut 0]];
|
2012-03-24 12:14:03 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn f(&&v: ~[mut ~[int]]) {
|
2012-07-14 15:55:41 -05:00
|
|
|
v[0] = ~[3]
|
2012-03-24 12:14:03 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn g(&&v: ~[const ~[const int]]) {
|
2012-03-24 12:14:03 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn h(&&v: ~[mut ~[mut int]]) {
|
2012-07-14 15:55:41 -05:00
|
|
|
v[0] = ~[mut 3]
|
2012-03-24 12:14:03 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn i(&&v: ~[mut ~[const int]]) {
|
2012-07-14 15:55:41 -05:00
|
|
|
v[0] = ~[mut 3]
|
2012-03-24 12:14:03 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn j(&&v: ~[~[const int]]) {
|
2012-03-24 12:14:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
f(v);
|
|
|
|
g(v);
|
2012-06-30 06:23:59 -05:00
|
|
|
h(v); //~ ERROR (values differ in mutability)
|
|
|
|
i(v); //~ ERROR (values differ in mutability)
|
|
|
|
j(v); //~ ERROR (values differ in mutability)
|
2012-03-24 12:14:03 -05:00
|
|
|
|
2012-06-30 06:23:59 -05:00
|
|
|
f(w); //~ ERROR (values differ in mutability)
|
2012-03-24 12:14:03 -05:00
|
|
|
g(w);
|
|
|
|
h(w);
|
2012-06-30 06:23:59 -05:00
|
|
|
i(w); //~ ERROR (values differ in mutability)
|
|
|
|
j(w); //~ ERROR (values differ in mutability)
|
2012-03-24 12:14:03 -05:00
|
|
|
|
|
|
|
// Note that without adding f() or h() to the mix, it is valid for
|
2012-06-29 18:26:56 -05:00
|
|
|
// x to have the type ~[mut ~[const int]], and thus we can safely
|
2012-03-24 12:14:03 -05:00
|
|
|
// call g() and i() but not j():
|
|
|
|
g(x);
|
|
|
|
i(x);
|
2012-06-30 06:23:59 -05:00
|
|
|
j(x); //~ ERROR (values differ in mutability)
|
2012-03-24 12:14:03 -05:00
|
|
|
}
|