test: De-[mut] (remove all mutable arrays from) the tests. rs=demuting
This commit is contained in:
parent
96bdc34930
commit
8fceee6c88
@ -1,15 +0,0 @@
|
|||||||
// 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() {
|
|
||||||
let mut x: ~[mut int] = ~[mut 3];
|
|
||||||
let y: ~[int] = ~[3];
|
|
||||||
x = y; //~ ERROR values differ in mutability
|
|
||||||
}
|
|
@ -11,7 +11,7 @@
|
|||||||
type point = { x: int, y: int };
|
type point = { x: int, y: int };
|
||||||
|
|
||||||
fn a() {
|
fn a() {
|
||||||
let mut p = ~[mut 1];
|
let mut p = ~[1];
|
||||||
|
|
||||||
// Create an immutable pointer into p's contents:
|
// Create an immutable pointer into p's contents:
|
||||||
let _q: &int = &p[0]; //~ NOTE loan of mutable vec content granted here
|
let _q: &int = &p[0]; //~ NOTE loan of mutable vec content granted here
|
||||||
@ -25,7 +25,7 @@ fn b() {
|
|||||||
// here we alias the mutable vector into an imm slice and try to
|
// here we alias the mutable vector into an imm slice and try to
|
||||||
// modify the original:
|
// modify the original:
|
||||||
|
|
||||||
let mut p = ~[mut 1];
|
let mut p = ~[1];
|
||||||
|
|
||||||
do borrow(p) { //~ NOTE loan of mutable vec content granted here
|
do borrow(p) { //~ NOTE loan of mutable vec content granted here
|
||||||
p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
|
p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
|
||||||
@ -35,7 +35,7 @@ fn b() {
|
|||||||
fn c() {
|
fn c() {
|
||||||
// Legal because the scope of the borrow does not include the
|
// Legal because the scope of the borrow does not include the
|
||||||
// modification:
|
// modification:
|
||||||
let mut p = ~[mut 1];
|
let mut p = ~[1];
|
||||||
borrow(p, ||{});
|
borrow(p, ||{});
|
||||||
p[0] = 5;
|
p[0] = 5;
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ fn takes_imm_elt(_v: &int, f: fn()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn has_mut_vec_and_does_not_try_to_change_it() {
|
fn has_mut_vec_and_does_not_try_to_change_it() {
|
||||||
let v = ~[mut 1, 2, 3];
|
let mut v = ~[1, 2, 3];
|
||||||
do takes_imm_elt(&v[0]) {
|
do takes_imm_elt(&v[0]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_mut_vec_but_tries_to_change_it() {
|
fn has_mut_vec_but_tries_to_change_it() {
|
||||||
let v = ~[mut 1, 2, 3];
|
let mut v = ~[1, 2, 3];
|
||||||
do takes_imm_elt(&v[0]) { //~ NOTE loan of mutable vec content granted here
|
do takes_imm_elt(&v[0]) { //~ NOTE loan of mutable vec content granted here
|
||||||
v[1] = 4; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
|
v[1] = 4; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ fn takes_const_elt(_v: &const int, f: fn()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn has_mut_vec_and_tries_to_change_it() {
|
fn has_mut_vec_and_tries_to_change_it() {
|
||||||
let v = ~[mut 1, 2, 3];
|
let mut v = ~[1, 2, 3];
|
||||||
do takes_const_elt(&const v[0]) {
|
do takes_const_elt(&const v[0]) {
|
||||||
v[1] = 4;
|
v[1] = 4;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
fn write(v: &[mut int]) {
|
fn write(v: &mut [int]) {
|
||||||
v[0] += 1;
|
v[0] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
// 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 want_slice(v: &[int]) -> int {
|
|
||||||
let mut sum = 0;
|
|
||||||
for vec::each(v) |i| { sum += *i; }
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn has_mut_vec(+v: @~[mut int]) -> int {
|
|
||||||
want_slice(*v) //~ ERROR illegal borrow unless pure
|
|
||||||
//~^ NOTE impure due to access to impure function
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert has_mut_vec(@~[mut 1, 2, 3]) == 6;
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
let a = [mut 1, 2, 3, 4];
|
let mut a = [1, 2, 3, 4];
|
||||||
let _ = match a {
|
let _ = match a {
|
||||||
[1, 2, ..tail] => tail,
|
[1, 2, ..tail] => tail,
|
||||||
_ => core::util::unreachable()
|
_ => core::util::unreachable()
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
// See #2969 -- error message should be improved
|
// See #2969 -- error message should be improved
|
||||||
let mut x = [mut 1, 2, 4];
|
let mut x = [1, 2, 4];
|
||||||
let v : &int = &x[2];
|
let v : &int = &x[2];
|
||||||
x[2] = 6;
|
x[2] = 6;
|
||||||
assert *v == 6;
|
assert *v == 6;
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// xfail-test
|
// xfail-test
|
||||||
fn function() -> &[mut int] {
|
fn function() -> &mut [int] {
|
||||||
let mut x: &static/[mut int] = &[mut 1,2,3];
|
let mut x: &static/mut [int] = &[1,2,3];
|
||||||
x[0] = 12345;
|
x[0] = 12345;
|
||||||
x //~ ERROR bad
|
x //~ ERROR bad
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
fn two_args<T>(x: T, y: T) { }
|
fn two_args<T>(x: T, y: T) { }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: ~[mut int] = ~[mut 3];
|
|
||||||
let y: ~[int] = ~[3];
|
|
||||||
let a: @mut int = @mut 3;
|
let a: @mut int = @mut 3;
|
||||||
let b: @int = @3;
|
let b: @int = @3;
|
||||||
|
|
||||||
@ -22,6 +20,5 @@ fn main() {
|
|||||||
// shortcoming of the current inference algorithm. These errors
|
// shortcoming of the current inference algorithm. These errors
|
||||||
// are *not* desirable.
|
// are *not* desirable.
|
||||||
|
|
||||||
two_args(x, y); //~ ERROR (values differ in mutability)
|
|
||||||
two_args(a, b); //~ ERROR (values differ in mutability)
|
two_args(a, b); //~ ERROR (values differ in mutability)
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// error-pattern: mismatched types
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let v = @mut ~[0];
|
|
||||||
|
|
||||||
fn f(&&v: @mut ~[const int]) {
|
|
||||||
*v = ~[mut 3]
|
|
||||||
}
|
|
||||||
|
|
||||||
f(v);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// error-pattern: mismatched types
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let v = @[mut @mut @mut @[0]];
|
|
||||||
|
|
||||||
fn f(&&v: @[mut @mut @mut @[const int]]) {
|
|
||||||
}
|
|
||||||
|
|
||||||
f(v);
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
// error-pattern: mismatched types
|
|
||||||
|
|
||||||
extern mod std;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut a = ~[0];
|
|
||||||
let v: *mut ~[int] = &mut a;
|
|
||||||
|
|
||||||
fn f(&&v: *mut ~[const int]) {
|
|
||||||
unsafe {
|
|
||||||
*v = ~[mut 3]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f(v);
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// 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: explicit type annot is required here
|
|
||||||
// because otherwise the inference gets smart
|
|
||||||
// and assigns a type of ~[mut ~[const int]].
|
|
||||||
let v: ~[mut ~[int]] = ~[mut ~[0]];
|
|
||||||
|
|
||||||
fn f(&&v: ~[mut ~[const int]]) {
|
|
||||||
v[0] = ~[mut 3]
|
|
||||||
}
|
|
||||||
|
|
||||||
f(v); //~ ERROR (values differ in mutability)
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// 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: explicit type annot is required here
|
|
||||||
// because otherwise the inference gets smart
|
|
||||||
// and assigns a type of ~[mut ~[const int]].
|
|
||||||
let v: ~[mut ~[mut int]] = ~[mut ~[mut 0]];
|
|
||||||
|
|
||||||
fn f(&&v: ~[mut ~[const int]]) {
|
|
||||||
v[0] = ~[3]
|
|
||||||
}
|
|
||||||
|
|
||||||
f(v); //~ ERROR (values differ in mutability)
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// 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: explicit type annot is required here
|
|
||||||
// because otherwise the inference gets smart
|
|
||||||
// and assigns a type of ~[mut ~[const int]].
|
|
||||||
let v: ~[mut ~[mut ~[int]]] = ~[mut ~[mut ~[0]]];
|
|
||||||
|
|
||||||
fn f(&&v: ~[mut ~[mut ~[const int]]]) {
|
|
||||||
v[0][1] = ~[mut 3]
|
|
||||||
}
|
|
||||||
|
|
||||||
f(v); //~ ERROR (values differ in mutability)
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
// 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)
|
|
||||||
}
|
|
@ -9,7 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
struct invariant {
|
struct invariant {
|
||||||
f: @[mut &int]
|
f: @mut [&int]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_same_lifetime(bi: invariant/&r) {
|
fn to_same_lifetime(bi: invariant/&r) {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// the right hand side in all cases. We are getting compiler errors
|
// the right hand side in all cases. We are getting compiler errors
|
||||||
// about this now, so I'm xfailing the test for now. -eholk
|
// about this now, so I'm xfailing the test for now. -eholk
|
||||||
|
|
||||||
fn add(i: ~[int], m: ~[mut int], c: ~[const int]) {
|
fn add(i: ~[int], mut m: ~[int], c: ~[const int]) {
|
||||||
|
|
||||||
// Check that:
|
// Check that:
|
||||||
// (1) vectors of any two mutabilities can be added
|
// (1) vectors of any two mutabilities can be added
|
||||||
@ -24,9 +24,9 @@ fn add(i: ~[int], m: ~[mut int], c: ~[const int]) {
|
|||||||
m + ~[3],
|
m + ~[3],
|
||||||
~[3]);
|
~[3]);
|
||||||
|
|
||||||
add(i + ~[mut 3],
|
add(i + ~[3],
|
||||||
m + ~[mut 3],
|
m + ~[3],
|
||||||
~[mut 3]);
|
~[3]);
|
||||||
|
|
||||||
add(i + i,
|
add(i + i,
|
||||||
m + i,
|
m + i,
|
||||||
@ -54,19 +54,19 @@ fn add(i: ~[int], m: ~[mut int], c: ~[const int]) {
|
|||||||
//~^ mismatched types
|
//~^ mismatched types
|
||||||
~[3]);
|
~[3]);
|
||||||
|
|
||||||
add(m + ~[mut 3], //~ ERROR mismatched types
|
add(m + ~[3], //~ ERROR mismatched types
|
||||||
m + ~[mut 3],
|
m + ~[3],
|
||||||
m + ~[mut 3]);
|
m + ~[3]);
|
||||||
|
|
||||||
add(i + ~[mut 3],
|
add(i + ~[3],
|
||||||
i + ~[mut 3], //~ ERROR mismatched types
|
i + ~[3], //~ ERROR mismatched types
|
||||||
i + ~[mut 3]);
|
i + ~[3]);
|
||||||
|
|
||||||
add(c + ~[mut 3], //~ ERROR binary operation + cannot be applied
|
add(c + ~[3], //~ ERROR binary operation + cannot be applied
|
||||||
//~^ mismatched types
|
//~^ mismatched types
|
||||||
c + ~[mut 3], //~ ERROR binary operation + cannot be applied
|
c + ~[3], //~ ERROR binary operation + cannot be applied
|
||||||
//~^ mismatched types
|
//~^ mismatched types
|
||||||
~[mut 3]);
|
~[3]);
|
||||||
|
|
||||||
add(m + i, //~ ERROR mismatched types
|
add(m + i, //~ ERROR mismatched types
|
||||||
m + i,
|
m + i,
|
||||||
|
Loading…
Reference in New Issue
Block a user