test: De-mut the test suite. rs=demuting

This commit is contained in:
Patrick Walton 2013-02-22 16:08:16 -08:00
parent 1144fdde1f
commit 82062a6348
65 changed files with 312 additions and 451 deletions

View File

@ -10,10 +10,10 @@
mod issue_3882 {
struct Completions {
mut len: libc::size_t,
len: libc::size_t,
}
extern mod c {
fn linenoiseAddCompletion(lc: *Completions);
fn linenoiseAddCompletion(lc: *mut Completions);
}
}

View File

@ -21,10 +21,10 @@ use io::WriterUtil;
fn LINE_LENGTH() -> uint { return 60u; }
struct MyRandom {
mut last: u32
last: u32
}
fn myrandom_next(r: @MyRandom, mx: u32) -> u32 {
fn myrandom_next(r: @mut MyRandom, mx: u32) -> u32 {
r.last = (r.last * 3877u32 + 29573u32) % 139968u32;
mx * r.last / 139968u32
}
@ -59,7 +59,7 @@ fn select_random(r: u32, genelist: ~[AminoAcids]) -> char {
fn make_random_fasta(wr: io::Writer, id: ~str, desc: ~str, genelist: ~[AminoAcids], n: int) {
wr.write_line(~">" + id + ~" " + desc);
let rng = @MyRandom {mut last: rand::Rng().next()};
let rng = @mut MyRandom {last: rand::Rng().next()};
let mut op: ~str = ~"";
for uint::range(0u, n as uint) |_i| {
str::push_char(&mut op, select_random(myrandom_next(rng, 100u32),

View File

@ -170,67 +170,80 @@ mod Body {
// was 4 * PI * PI originally
pub const DAYS_PER_YEAR: float = 365.24;
pub struct Props
{mut x: float,
mut y: float,
mut z: float,
mut vx: float,
mut vy: float,
mut vz: float,
mass: float}
pub struct Props {
x: float,
y: float,
z: float,
vx: float,
vy: float,
vz: float,
mass: float
}
pub fn jupiter() -> Body::Props {
return Props {mut x: 4.84143144246472090e+00,
mut y: -1.16032004402742839e+00,
mut z: -1.03622044471123109e-01,
mut vx: 1.66007664274403694e-03 * DAYS_PER_YEAR,
mut vy: 7.69901118419740425e-03 * DAYS_PER_YEAR,
mut vz: -6.90460016972063023e-05 * DAYS_PER_YEAR,
mass: 9.54791938424326609e-04 * SOLAR_MASS};
return Props {
x: 4.84143144246472090e+00,
y: -1.16032004402742839e+00,
z: -1.03622044471123109e-01,
vx: 1.66007664274403694e-03 * DAYS_PER_YEAR,
vy: 7.69901118419740425e-03 * DAYS_PER_YEAR,
vz: -6.90460016972063023e-05 * DAYS_PER_YEAR,
mass: 9.54791938424326609e-04 * SOLAR_MASS
};
}
pub fn saturn() -> Body::Props {
return Props {mut x: 8.34336671824457987e+00,
mut y: 4.12479856412430479e+00,
mut z: -4.03523417114321381e-01,
mut vx: -2.76742510726862411e-03 * DAYS_PER_YEAR,
mut vy: 4.99852801234917238e-03 * DAYS_PER_YEAR,
mut vz: 2.30417297573763929e-05 * DAYS_PER_YEAR,
mass: 2.85885980666130812e-04 * SOLAR_MASS};
return Props {
x: 8.34336671824457987e+00,
y: 4.12479856412430479e+00,
z: -4.03523417114321381e-01,
vx: -2.76742510726862411e-03 * DAYS_PER_YEAR,
vy: 4.99852801234917238e-03 * DAYS_PER_YEAR,
vz: 2.30417297573763929e-05 * DAYS_PER_YEAR,
mass: 2.85885980666130812e-04 * SOLAR_MASS
};
}
pub fn uranus() -> Body::Props {
return Props {mut x: 1.28943695621391310e+01,
mut y: -1.51111514016986312e+01,
mut z: -2.23307578892655734e-01,
mut vx: 2.96460137564761618e-03 * DAYS_PER_YEAR,
mut vy: 2.37847173959480950e-03 * DAYS_PER_YEAR,
mut vz: -2.96589568540237556e-05 * DAYS_PER_YEAR,
mass: 4.36624404335156298e-05 * SOLAR_MASS};
return Props {
x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01,
vx: 2.96460137564761618e-03 * DAYS_PER_YEAR,
vy: 2.37847173959480950e-03 * DAYS_PER_YEAR,
vz: -2.96589568540237556e-05 * DAYS_PER_YEAR,
mass: 4.36624404335156298e-05 * SOLAR_MASS
};
}
pub fn neptune() -> Body::Props {
return Props {mut x: 1.53796971148509165e+01,
mut y: -2.59193146099879641e+01,
mut z: 1.79258772950371181e-01,
mut vx: 2.68067772490389322e-03 * DAYS_PER_YEAR,
mut vy: 1.62824170038242295e-03 * DAYS_PER_YEAR,
mut vz: -9.51592254519715870e-05 * DAYS_PER_YEAR,
mass: 5.15138902046611451e-05 * SOLAR_MASS};
return Props {
x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01,
vx: 2.68067772490389322e-03 * DAYS_PER_YEAR,
vy: 1.62824170038242295e-03 * DAYS_PER_YEAR,
vz: -9.51592254519715870e-05 * DAYS_PER_YEAR,
mass: 5.15138902046611451e-05 * SOLAR_MASS
};
}
pub fn sun() -> Body::Props {
return Props {mut x: 0.0,
mut y: 0.0,
mut z: 0.0,
mut vx: 0.0,
mut vy: 0.0,
mut vz: 0.0,
mass: SOLAR_MASS};
return Props {
x: 0.0,
y: 0.0,
z: 0.0,
vx: 0.0,
vy: 0.0,
vz: 0.0,
mass: SOLAR_MASS
};
}
pub fn offset_momentum(props: &mut Body::Props,
px: float, py: float, pz: float) {
px: float,
py: float,
pz: float) {
props.vx = -px / SOLAR_MASS;
props.vy = -py / SOLAR_MASS;
props.vz = -pz / SOLAR_MASS;

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct point {x: int, mut y: int }
struct point { x: int, y: int }
fn a() {
let mut p = point {x: 3, y: 4};
@ -20,22 +20,13 @@ fn a() {
p.x = 5; //~ ERROR assigning to mutable field prohibited due to outstanding loan
}
fn b() {
let mut p = point {x: 3, mut y: 4};
// This assignment is legal because `y` is inherently mutable (and
// hence &_q.y is &mut int).
let _q = &p;
p.y = 5;
}
fn c() {
// this is sort of the opposite. We take a loan to the interior of `p`
// and then try to overwrite `p` as a whole.
let mut p = point {x: 3, mut y: 4};
let mut p = point {x: 3, y: 4};
let _q = &p.y; //~ NOTE loan of mutable local variable granted here
p = point {x: 5, mut y: 7};//~ ERROR assigning to mutable local variable prohibited due to outstanding loan
p = point {x: 5, y: 7};//~ ERROR assigning to mutable local variable prohibited due to outstanding loan
copy p;
}
@ -43,7 +34,7 @@ fn d() {
// just for completeness's sake, the easy case, where we take the
// address of a subcomponent and then modify that subcomponent:
let mut p = point {x: 3, mut y: 4};
let mut p = point {x: 3, y: 4};
let _q = &p.y; //~ NOTE loan of mutable field granted here
p.y = 5; //~ ERROR assigning to mutable field prohibited due to outstanding loan
copy p;

View File

@ -10,7 +10,7 @@
// xfail-test #2978
fn call(x: @{mut f: fn~()}) {
fn call(x: @{f: fn~()}) {
x.f(); //~ ERROR foo
//~^ NOTE bar
}

View File

@ -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.
fn each<T>(x: &[T], op: fn(elem: &T) -> bool) {
uint::range(0, x.len(), |i| op(&x[i]));
}
struct A {
mut a: int
}
fn main() {
let x = [A {mut a: 0}];
for each(x) |y| {
let z = &y.a; //~ ERROR illegal borrow unless pure
x[0].a = 10; //~ NOTE impure due to assigning to mutable field
log(error, z);
}
}

View File

@ -1,25 +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 each<T>(x: &[T], op: fn(elem: &T) -> bool) {
uint::range(0, x.len(), |i| op(&x[i]));
}
fn main() {
struct A {
mut a: int
}
let x = ~[A {mut a: 0}];
for each(x) |y| {
let z = &y.a; //~ ERROR illegal borrow unless pure
x[0].a = 10; //~ NOTE impure due to assigning to mutable field
log(error, z);
}
}

View File

@ -1,30 +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.
struct Foo {
mut x: uint
}
struct Bar {
foo: Foo
}
fn main() {
let mut b = Bar { foo: Foo { x: 3 } };
let p = &b;
let q = &mut b.foo.x;
let r = &p.foo.x; //~ ERROR illegal borrow unless pure
let s = &b.foo.x; //~ ERROR loan of mutable field as immutable conflicts with prior loan
io::println(fmt!("*r = %u", *r));
io::println(fmt!("*r = %u", *s));
*q += 1;
io::println(fmt!("*r = %u", *r));
io::println(fmt!("*r = %u", *s));
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct node_ {
mut a: ~cycle
a: ~cycle
}
enum cycle {
@ -17,11 +17,11 @@ enum cycle {
empty
}
fn main() {
let x = ~node(node_ {mut a: ~empty});
let mut x = ~node(node_ {a: ~empty});
// Create a cycle!
match *x { //~ NOTE loan of immutable local variable granted here
node(ref y) => {
y.a = x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
match *x { //~ NOTE loan of mutable local variable granted here
node(ref mut y) => {
y.a = x; //~ ERROR moving out of mutable local variable prohibited due to outstanding loan
}
empty => {}
};

View File

@ -14,10 +14,6 @@ fn box_mut(v: @mut ~int) {
borrow(*v); //~ ERROR illegal borrow unless pure
}
fn box_rec_mut(v: @{mut f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}
fn box_mut_rec(v: @mut {f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}
@ -42,14 +38,6 @@ fn box_const(v: @const ~int) {
borrow(*v); //~ ERROR illegal borrow unless pure
}
fn box_rec_const(v: @{const f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}
fn box_recs_const(v: @{f: {g: {const h: ~int}}}) {
borrow(v.f.g.h); //~ ERROR illegal borrow unless pure
}
fn box_const_rec(v: @const {f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}

View File

@ -14,10 +14,6 @@ fn box_mut(v: &mut ~int) {
borrow(*v); // OK: &mut -> &imm
}
fn box_rec_mut(v: &{mut f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}
fn box_mut_rec(v: &mut {f: ~int}) {
borrow(v.f); // OK: &mut -> &imm
}
@ -42,14 +38,6 @@ fn box_const(v: &const ~int) {
borrow(*v); //~ ERROR illegal borrow unless pure
}
fn box_rec_const(v: &{const f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}
fn box_recs_const(v: &{f: {g: {const h: ~int}}}) {
borrow(v.f.g.h); //~ ERROR illegal borrow unless pure
}
fn box_const_rec(v: &const {f: ~int}) {
borrow(v.f); //~ ERROR illegal borrow unless pure
}

View File

@ -9,8 +9,8 @@
// except according to those terms.
// xfail-test
type T = { mut f: fn@() };
type S = { f: fn@() };
struct T { f: fn@() };
struct S { f: fn@() };
fn fooS(t: S) {
}
@ -23,11 +23,11 @@ fn bar() {
fn main() {
let x: fn@() = bar;
fooS({f: x});
fooS({f: bar});
fooS(S {f: x});
fooS(S {f: bar});
let x: fn@() = bar;
fooT({mut f: x});
fooT({mut f: bar});
fooT(T {f: x});
fooT(T {f: bar});
}

View File

@ -13,11 +13,11 @@ extern mod std;
fn siphash(k0 : u64) {
struct siphash {
mut v0: u64,
v0: u64,
}
impl siphash {
fn reset() {
fn reset(&mut self) {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
//~^ ERROR unresolved name: k0
}

View File

@ -11,10 +11,10 @@
fn main() {
let needlesArr: ~[char] = ~['a', 'f'];
do vec::foldr(needlesArr) |x, y| {
//~^ ERROR 2 parameters were supplied (including the closure passed by the `do` keyword)
//~^^ ERROR Unconstrained region variable #2
//
// this last error is, um, non-ideal.
//~^ ERROR Unconstrained region variable #2
}
//~^ ERROR 2 parameters were supplied (including the closure passed by the `do` keyword)
//
// the first error is, um, non-ideal.
}

View File

@ -12,7 +12,7 @@
// error-pattern: instantiating a type parameter with an incompatible type
struct S<T:Const> {
s: T,
mut cant_nest: ()
cant_nest: ()
}
fn main() {

View File

@ -10,7 +10,7 @@
fn foo<T>() {
struct foo {
mut x: T, //~ ERROR attempt to use a type argument out of scope
x: T, //~ ERROR attempt to use a type argument out of scope
//~^ ERROR use of undeclared type name
}

View File

@ -10,7 +10,7 @@
// xfail-test
struct HTMLImageData {
mut image: Option<~str>
image: Option<~str>
}
struct ElementData {
@ -30,7 +30,7 @@ enum NodeData = {
};
fn main() {
let id = HTMLImageData { image: None };
let mut id = HTMLImageData { image: None };
let ed = ElementData { kind: ~HTMLImageElement(id) };
let n = NodeData({kind : ~Element(ed)});
match n.kind {

View File

@ -11,8 +11,8 @@
// xfail-test
struct Point {
mut x: float,
mut y: float,
x: float,
y: float,
}
impl ToStr for Point { //~ ERROR implements a method not defined in the trait

View File

@ -10,11 +10,15 @@
// error-pattern: mismatched types
fn main() {
let v = {mut g: ~[0]};
struct S {
g: ~[int]
}
fn f(&&v: {mut g: ~[const int]}) {
v.g = ~[mut 3]
fn main() {
let v = S {g: ~[0]};
fn f(&&v: {g: ~[const int]}) {
v.g = ~[3]
}
f(v);

View File

@ -1,58 +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.
// Test that various non const things are rejected.
fn foo<T:Const>(_x: T) { }
struct r {
x:int,
}
impl Drop for r {
fn finalize(&self) {}
}
fn r(x:int) -> r {
r {
x: x
}
}
struct r2 {
x:@mut int,
}
impl Drop for r2 {
fn finalize(&self) {}
}
fn r2(x:@mut int) -> r2 {
r2 {
x: x
}
}
fn main() {
struct A<T> { f: T }
struct B<T> { mut f: T }
foo(A {f: 3});
foo(B {mut f: 3}); //~ ERROR does not fulfill `Const`
foo(~[1]);
foo(~[mut 1]); //~ ERROR does not fulfill `Const`
foo(~1);
foo(~mut 1); //~ ERROR does not fulfill `Const`
foo(@1);
foo(@mut 1); //~ ERROR does not fulfill `Const`
foo(r(1)); // this is okay now.
foo(r2(@mut 1)); //~ ERROR does not fulfill `Const`
foo(A {f: B {mut f: 1}}); //~ ERROR does not fulfill `Const`
}

View File

@ -10,20 +10,20 @@
// Check that pure functions cannot modify aliased state.
pure fn modify_in_ref(&&sum: {mut f: int}) {
sum.f = 3; //~ ERROR assigning to mutable field prohibited in pure context
struct S {
f: int,
}
pure fn modify_in_box(sum: @mut {f: int}) {
pure fn modify_in_box(sum: @mut S) {
sum.f = 3; //~ ERROR assigning to mutable field prohibited in pure context
}
trait modify_in_box_rec {
pure fn modify_in_box_rec(sum: @{mut f: int});
pure fn modify_in_box_rec(sum: @mut S);
}
impl modify_in_box_rec for int {
pure fn modify_in_box_rec(sum: @{mut f: int}) {
pure fn modify_in_box_rec(sum: @mut S) {
sum.f = self; //~ ERROR assigning to mutable field prohibited in pure context
}
}

View File

@ -9,16 +9,16 @@
// except according to those terms.
struct dog {
mut cats_chased: uint,
cats_chased: uint,
}
impl dog {
fn chase_cat() {
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR illegal borrow
fn chase_cat(&mut self) {
let p: &static/mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
*p += 1u;
}
fn chase_cat_2() {
fn chase_cat_2(&mut self) {
let p: &blk/mut uint = &mut self.cats_chased;
*p += 1u;
}
@ -31,7 +31,7 @@ fn dog() -> dog {
}
fn main() {
let d = dog();
let mut d = dog();
d.chase_cat();
debug!("cats_chased: %u", d.cats_chased);
}

View File

@ -9,13 +9,13 @@
// except according to those terms.
struct dog {
mut food: uint,
food: uint,
}
impl dog {
fn chase_cat() {
fn chase_cat(&mut self) {
for uint::range(0u, 10u) |_i| {
let p: &'static mut uint = &mut self.food; //~ ERROR illegal borrow
let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
*p = 3u;
}
}

View File

@ -17,7 +17,7 @@ mod argparse {
name: &str,
desc: &str,
max_count: uint,
mut value: uint
value: uint
}
pub fn flag(name: &r/str, desc: &r/str) -> Flag/&r {

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct invariant {
mut f: &int
f: &int
}
fn to_same_lifetime(bi: invariant/&r) {
@ -17,8 +17,8 @@ fn to_same_lifetime(bi: invariant/&r) {
}
fn to_shorter_lifetime(bi: invariant/&r) {
let bj: invariant/&blk = bi; //~ ERROR mismatched types
}
let bj: invariant/&blk = bi;
}
fn to_longer_lifetime(bi: invariant/&r) -> invariant/&static {
bi //~ ERROR mismatched types

View File

@ -17,14 +17,16 @@ trait foo {
fn any_int() -> &int;
}
type with_foo = {mut f: foo};
struct with_foo {
f: foo
}
trait set_foo_foo {
fn set_foo(f: foo);
fn set_foo(&mut self, f: foo);
}
impl set_foo_foo for with_foo {
fn set_foo(f: foo) {
fn set_foo(&mut self, f: foo) {
self.f = f; //~ ERROR mismatched types: expected `@foo/&self` but found `@foo/&`
}
}
@ -35,14 +37,16 @@ trait bar {
fn any_int() -> &int;
}
type with_bar = {mut f: bar};
struct with_bar {
f: bar
}
trait set_foo_bar {
fn set_foo(f: bar);
fn set_foo(&mut self, f: bar);
}
impl set_foo_bar for with_bar {
fn set_foo(f: bar) {
fn set_foo(&mut self, f: bar) {
self.f = f;
}
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct box_impl<T> {
mut f: T,
f: T,
}
fn box_impl<T>(f: T) -> box_impl<T> {

View File

@ -9,8 +9,9 @@
// except according to those terms.
struct box<T> {
mut f: T
f: T
}
enum box_impl<T> = box<T>;
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
@ -18,12 +19,12 @@ fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
}
fn main() {
let b = box_impl::<@int>(box::<@int> {mut f: @3});
let b = box_impl::<@int>(box::<@int> {f: @3});
set_box_impl(b, @mut 5);
//~^ ERROR values differ in mutability
// No error when type of parameter actually IS @const int
let x: @const int = @3; // only way I could find to upcast
let b = box_impl::<@const int>(box::<@const int>{mut f: x});
let b = box_impl::<@const int>(box::<@const int>{f: x});
set_box_impl(b, @mut 5);
}

View File

@ -14,7 +14,7 @@ trait box_trait<T> {
}
struct box<T> {
mut f: T
f: T
}
enum box_impl<T> = box<T>;
@ -33,7 +33,7 @@ fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
}
fn main() {
let b = box_impl::<@int>(box::<@int> {mut f: @3});
let b = box_impl::<@int>(box::<@int> {f: @3});
set_box_trait(b as box_trait::<@int>, @mut 5);
//~^ ERROR values differ in mutability
set_box_impl(b, @mut 5);

View File

@ -16,10 +16,10 @@ fn test1() { let val = @0; { } *val; }
fn test2() -> int { let val = @0; { } *val }
struct S { mut eax: int }
struct S { eax: int }
fn test3() {
let regs = @S {mut eax: 0};
let regs = @mut S {eax: 0};
match true { true => { } _ => { } }
(*regs).eax = 1;
}

View File

@ -20,12 +20,12 @@ use syntax::parse::parser;
fn new_parse_sess() -> parser::parse_sess {
let cm = codemap::new_codemap();
let handler = diagnostic::mk_handler(option::none);
let sess = @{
let sess = @mut {
cm: cm,
mut next_id: 1,
next_id: 1,
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
mut chpos: 0u,
mut byte_pos: 0u
chpos: 0u,
byte_pos: 0u
};
return sess;
}

View File

@ -15,11 +15,11 @@ struct Pair<A,B> {
enum RecEnum<A> = Rec<A>;
struct Rec<A> {
val: A,
mut rec: Option<@RecEnum<A>>
rec: Option<@mut RecEnum<A>>
}
fn make_cycle<A:Copy>(a: A) {
let g: @RecEnum<A> = @RecEnum(Rec {val: a, mut rec: None});
let g: @mut RecEnum<A> = @mut RecEnum(Rec {val: a, rec: None});
g.rec = Some(g);
}

View File

@ -10,8 +10,8 @@
enum option<T> { some(T), none, }
struct R<T> {mut v: ~[option<T>]}
struct R<T> {v: ~[option<T>]}
fn f<T>() -> ~[T] { return ~[]; }
pub fn main() { let r: R<int> = R {mut v: ~[]}; r.v = f(); }
pub fn main() { let mut r: R<int> = R {v: ~[]}; r.v = f(); }

View File

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Pair { mut a: ~int, mut b: ~int }
struct Pair { a: ~int, b: ~int }
pub fn main() {
let x = ~Pair {mut a: ~10, b: ~20};
let mut x = ~Pair {a: ~10, b: ~20};
match x {
~Pair {a: ref mut a, b: ref b} => {
~Pair {a: ref mut a, b: ref mut b} => {
assert **a == 10; *a = ~30; assert **a == 30;
}
}

View File

@ -10,7 +10,7 @@
// xfail-fast
struct X { mut x: int }
struct X { x: int }
fn f1(a: &mut X, b: &mut int, -c: int) -> int {
let r = a.x + *b + c;
@ -19,13 +19,13 @@ fn f1(a: &mut X, b: &mut int, -c: int) -> int {
return r;
}
fn f2(a: int, f: fn(int)) -> int { f(1); return a; }
fn f2(a: int, f: &fn(int)) -> int { f(1); return a; }
pub fn main() {
let mut a = X {mut x: 1}, b = 2, c = 3;
let mut a = X {x: 1}, b = 2, c = 3;
assert (f1(&mut a, &mut b, c) == 6);
assert (a.x == 0);
assert (b == 10);
assert (f2(a.x, |x| a.x = 50 ) == 0);
assert (f2(a.x, |x| a.x = 50) == 0);
assert (a.x == 50);
}

View File

@ -86,9 +86,10 @@ extern mod test {
pub fn get_task_id() -> libc::intptr_t;
}
#[deriving_eq]
struct p {
mut x: int,
mut y: int,
x: int,
y: int,
}
fn p(x: int, y: int) -> p {
@ -98,16 +99,9 @@ fn p(x: int, y: int) -> p {
}
}
impl cmp::Eq for p {
pure fn eq(&self, other: &p) -> bool {
(*self).x == (*other).x && (*self).y == (*other).y
}
pure fn ne(&self, other: &p) -> bool { !(*self).eq(other) }
}
fn test_class() {
let q = p(1, 2);
let r = p(1, 2);
let mut q = p(1, 2);
let mut r = p(1, 2);
unsafe {
error!("q = %x, r = %x",

View File

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct F { mut f: ~[int] }
struct F { f: ~[int] }
fn impure(_v: &[int]) {
}
pub fn main() {
let x = F {f: ~[3]};
let mut x = F {f: ~[3]};
match x {
F {f: ref mut v} => {

View File

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum foo = {mut bar: baz};
struct foo {bar: baz}
enum baz = @{mut baz: int};
struct baz_ {baz: int}
type baz = @mut baz_;
trait frob {
fn frob();

View File

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct F { mut f: @G }
struct F { f: @G }
struct G { g: ~[int] }
pub fn main() {
let rec = @F {mut f: @G {g: ~[1, 2, 3]}};
let rec = @mut F {f: @G {g: ~[1, 2, 3]}};
while rec.f.g.len() == 23 {}
}

View File

@ -10,9 +10,9 @@
fn borrow<T>(x: &r/T) -> &r/T {x}
struct Rec { mut f: @int }
struct Rec { f: @int }
pub fn main() {
let rec = @Rec {mut f: @22};
let rec = @mut Rec {f: @22};
while *borrow(rec.f) == 23 {}
}

View File

@ -12,7 +12,7 @@
// the boxed type parameter
type Tree<T> = {
mut parent: Option<T>,
parent: Option<T>,
};
fn empty<T>() -> Tree<T> { fail!() }
@ -28,7 +28,7 @@ fn Box() -> Box {
}
enum layout_data = {
mut box: Option<@Box>
box: Option<@Box>
};
pub fn main() { }

View File

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct foo { mut z : fn@() }
struct foo { z: fn@() }
fn nop() { }
fn nop_foo(_x : @foo) { }
fn nop_foo(_x : @mut foo) { }
pub fn main() {
let w = @foo{ mut z: || nop() };
let x : fn@() = || nop_foo(w);
let w = @mut foo{ z: || nop() };
let x: fn@() = || nop_foo(w);
w.z = x;
}

View File

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct foo { mut z : fn@() }
struct foo { z: fn@() }
fn nop() { }
fn nop_foo(_y: @int, _x : @foo) { }
fn nop_foo(_y: @int, _x: @mut foo) { }
fn o() -> @int { @10 }
pub fn main() {
let w = @foo { mut z: || nop() };
let w = @mut foo { z: || nop() };
let x : fn@() = || nop_foo(o(), w);
w.z = x;
}

View File

@ -46,7 +46,7 @@ struct thing {
x: A
}
struct A { mut a: @int }
struct A { a: @int }
fn thing(x: A) -> thing {
thing {
@ -67,14 +67,14 @@ impl Nus for thing { fn f(&self) {} }
pub fn main() {
let x = @thing(A {mut a: @10});
let x = @thing(A {a: @10});
assert x.foo() == 10;
assert x.quux() == 10;
let y = ~thing(A {mut a: @10});
let y = ~thing(A {a: @10});
assert (copy y).bar() == 10;
assert y.quux() == 10;
let z = thing(A {mut a: @11});
let z = thing(A {a: @11});
assert z.spam() == 11;
}

View File

@ -10,17 +10,18 @@
// xfail-fast
fn f(arg: &A) {
fn f(arg: &mut A) {
arg.a = 100;
}
struct A { mut a: int }
struct A { a: int }
pub fn main() {
let x = A {a: 10};
f(&x);
let mut x = A {a: 10};
f(&mut x);
assert x.a == 100;
x.a = 20;
f(&copy x);
let mut y = copy x;
f(&mut y);
assert x.a == 20;
}

View File

@ -12,13 +12,13 @@
// -*- rust -*-
struct Point {x: int, y: int, mut z: int}
struct Point {x: int, y: int, z: int}
fn f(p: @Point) { assert (p.z == 12); p.z = 13; assert (p.z == 13); }
fn f(p: @mut Point) { assert (p.z == 12); p.z = 13; assert (p.z == 13); }
pub fn main() {
let a: Point = Point {x: 10, y: 11, mut z: 12};
let b: @Point = @copy a;
let a: Point = Point {x: 10, y: 11, z: 12};
let b: @mut Point = @mut copy a;
assert (b.z == 12);
f(b);
assert (a.z == 12);

View File

@ -9,7 +9,7 @@
// except according to those terms.
struct cat {
mut meow: fn@(),
meow: fn@(),
}
fn cat() -> cat {

View File

@ -15,9 +15,9 @@ pub mod pipes {
use core::cast::{forget, transmute};
pub struct Stuff<T> {
mut state: state,
mut blocked_task: Option<task::Task>,
mut payload: Option<T>
state: state,
blocked_task: Option<task::Task>,
payload: Option<T>
}
#[deriving_eq]
@ -29,17 +29,17 @@ pub mod pipes {
}
pub type packet<T> = {
mut state: state,
mut blocked_task: Option<task::Task>,
mut payload: Option<T>
state: state,
blocked_task: Option<task::Task>,
payload: Option<T>
};
pub fn packet<T:Owned>() -> *packet<T> {
unsafe {
let p: *packet<T> = cast::transmute(~Stuff{
mut state: empty,
mut blocked_task: None::<task::Task>,
mut payload: None::<T>
state: empty,
blocked_task: None::<task::Task>,
payload: None::<T>
});
p
}
@ -70,9 +70,9 @@ pub mod pipes {
}
}
pub fn send<T:Owned>(-p: send_packet<T>, -payload: T) {
let p = p.unwrap();
let p = unsafe { uniquify(p) };
pub fn send<T:Owned>(mut p: send_packet<T>, -payload: T) {
let mut p = p.unwrap();
let mut p = unsafe { uniquify(p) };
assert (*p).payload.is_none();
(*p).payload = Some(payload);
let old_state = swap_state_rel(&mut (*p).state, full);
@ -96,9 +96,9 @@ pub mod pipes {
}
}
pub fn recv<T:Owned>(-p: recv_packet<T>) -> Option<T> {
let p = p.unwrap();
let p = unsafe { uniquify(p) };
pub fn recv<T:Owned>(mut p: recv_packet<T>) -> Option<T> {
let mut p = p.unwrap();
let mut p = unsafe { uniquify(p) };
loop {
let old_state = swap_state_acq(&mut (*p).state,
blocked);
@ -117,8 +117,8 @@ pub mod pipes {
}
}
pub fn sender_terminate<T:Owned>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
pub fn sender_terminate<T:Owned>(mut p: *packet<T>) {
let mut p = unsafe { uniquify(p) };
match swap_state_rel(&mut (*p).state, terminated) {
empty | blocked => {
// The receiver will eventually clean up.
@ -134,8 +134,8 @@ pub mod pipes {
}
}
pub fn receiver_terminate<T:Owned>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
pub fn receiver_terminate<T:Owned>(mut p: *packet<T>) {
let mut p = unsafe { uniquify(p) };
match swap_state_rel(&mut (*p).state, terminated) {
empty => {
// the sender will clean up
@ -152,21 +152,25 @@ pub mod pipes {
}
pub struct send_packet<T> {
mut p: Option<*packet<T>>,
p: Option<*packet<T>>,
}
pub impl<T:Owned> Drop for send_packet<T> {
fn finalize(&self) {
if self.p != None {
let mut p = None;
p <-> self.p;
sender_terminate(option::unwrap(p))
unsafe {
if self.p != None {
let mut p = None;
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
sender_terminate(option::unwrap(p))
}
}
}
}
pub impl<T:Owned> send_packet<T> {
fn unwrap() -> *packet<T> {
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
option::unwrap(p)
@ -180,21 +184,25 @@ pub mod pipes {
}
pub struct recv_packet<T> {
mut p: Option<*packet<T>>,
p: Option<*packet<T>>,
}
pub impl<T:Owned> Drop for recv_packet<T> {
fn finalize(&self) {
if self.p != None {
let mut p = None;
p <-> self.p;
receiver_terminate(option::unwrap(p))
unsafe {
if self.p != None {
let mut p = None;
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
receiver_terminate(option::unwrap(p))
}
}
}
}
pub impl<T:Owned> recv_packet<T> {
fn unwrap() -> *packet<T> {
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
option::unwrap(p)

View File

@ -9,8 +9,8 @@
// except according to those terms.
struct trie_node {
mut content: ~[~str],
mut children: ~[trie_node],
content: ~[~str],
children: ~[trie_node],
}
fn print_str_vector(vector: ~[~str]) {
@ -20,7 +20,7 @@ fn print_str_vector(vector: ~[~str]) {
}
pub fn main() {
let node: trie_node = trie_node {
let mut node: trie_node = trie_node {
content: ~[],
children: ~[]
};

View File

@ -10,17 +10,17 @@
struct list<T> {
element: &self/T,
mut next: Option<@list<T>>
next: Option<@mut list<T>>
}
impl<T> list<T>{
fn addEnd(&self, element: &self/T) {
fn addEnd(&mut self, element: &self/T) {
let newList = list {
element: element,
next: option::None
};
self.next = Some(@(newList));
self.next = Some(@mut newList);
}
}

View File

@ -20,7 +20,7 @@ fn exit(+print: ErrPrinter, prog: &str, arg: &str) {
}
struct X {
mut err: ErrPrinter
err: ErrPrinter
}
impl X {

View File

@ -10,7 +10,7 @@
// xfail-test
trait Positioned<S> {
fn SetX(&self, S);
fn SetX(&mut self, S);
fn X(&self) -> S;
}
@ -21,10 +21,10 @@ trait Movable<S, T>: Positioned<T> {
}
}
struct Point { mut x: int, mut y: int }
struct Point { x: int, y: int }
impl Positioned<int> for Point {
fn SetX(&self, x: int) {
fn SetX(&mut self, x: int) {
self.x = x;
}
fn X(&self) -> int {

View File

@ -13,10 +13,10 @@
extern mod issue_3979_traits;
use issue_3979_traits::*;
struct Point { mut x: int, mut y: int }
struct Point { x: int, y: int }
impl Positioned for Point {
fn SetX(&self, x: int) {
fn SetX(&mut self, x: int) {
self.x = x;
}
fn X(&self) -> int {
@ -24,10 +24,10 @@ impl Positioned for Point {
}
}
impl Point: Movable;
impl Movable for Point;
pub fn main() {
let p = Point{ x: 1, y: 2};
let mut p = Point{ x: 1, y: 2};
p.translate(3);
assert p.X() == 4;
}

View File

@ -1,3 +1,6 @@
// xfail-test
// Reason: ICE with explicit self
// 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.
@ -9,21 +12,22 @@
// except according to those terms.
trait Positioned {
fn SetX(&self, int);
fn SetX(&mut self, int);
fn X(&self) -> int;
}
#[allow(default_methods)]
trait Movable: Positioned {
fn translate(&self, dx: int) {
self.SetX(self.X() + dx);
fn translate(&mut self, dx: int) {
let x = self.X();
self.SetX(x + dx);
}
}
struct Point { mut x: int, mut y: int }
struct Point { x: int, y: int }
impl Positioned for Point {
fn SetX(&self, x: int) {
fn SetX(&mut self, x: int) {
self.x = x;
}
fn X(&self) -> int {
@ -34,7 +38,7 @@ impl Positioned for Point {
impl Movable for Point;
pub fn main() {
let p = Point{ x: 1, y: 2};
let mut p = Point{ x: 1, y: 2};
p.translate(3);
assert p.X() == 4;
}

View File

@ -12,10 +12,10 @@
// resolved when we finish typechecking the fn@.
struct Refs { mut refs: ~[int], n: int }
struct Refs { refs: ~[int], n: int }
pub fn main() {
let e = @Refs{mut refs: ~[], n: 0};
let e = @mut Refs{refs: ~[], n: 0};
let f = fn@ () { log(error, e.n); };
e.refs += ~[1];
}

View File

@ -15,17 +15,17 @@ enum option<T> {
some(T),
}
struct Smallintmap<T> {mut v: ~[option<T>]}
struct Smallintmap<T> {v: ~[option<T>]}
struct V<T> { v: ~[option<T>] }
fn mk<T>() -> @Smallintmap<T> {
fn mk<T>() -> @mut Smallintmap<T> {
let mut v: ~[option<T>] = ~[];
return @Smallintmap {mut v: v};
return @mut Smallintmap {v: v};
}
fn f<T,U>() {
let sim = mk::<U>();
let mut sim = mk::<U>();
log(error, sim);
}

View File

@ -12,14 +12,14 @@
// -*- rust -*-
extern mod std;
type cell = {mut c: @list};
type cell = {c: @list};
enum list { link(@cell), nil, }
enum list { link(@mut cell), nil, }
pub fn main() {
let first: @cell = @{mut c: @nil()};
let second: @cell = @{mut c: @link(first)};
let first: @cell = @mut {c: @nil()};
let second: @cell = @mut {c: @link(first)};
first._0 = @link(second);
sys.rustrt.gc();
let third: @cell = @{mut c: @nil()};
let third: @cell = @mut {c: @nil()};
}

View File

@ -11,17 +11,17 @@
struct A { a: int, b: @int }
struct B { a: int, b: C }
struct D { a: int, d: C }
struct C { mut c: int }
struct C { c: int }
pub fn main() {
match A {a: 10, b: @20} {
x@A {a, b: @20} => { assert x.a == 10; assert a == 10; }
A {b, _} => { fail!(); }
}
let x@B {b, _} = B {a: 10, b: C {mut c: 20}};
let mut x@B {b, _} = B {a: 10, b: C {c: 20}};
x.b.c = 30;
assert b.c == 20;
let y@D {d, _} = D {a: 10, d: C {mut c: 20}};
let mut y@D {d, _} = D {a: 10, d: C {c: 20}};
y.d.c = 30;
assert d.c == 20;
}

View File

@ -470,12 +470,12 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
}
}
enum my_visitor = @Stuff;
enum my_visitor = @mut Stuff;
struct Stuff {
mut ptr1: *c_void,
mut ptr2: *c_void,
mut vals: ~[~str]
ptr1: *c_void,
ptr2: *c_void,
vals: ~[~str]
}
impl my_visitor {
@ -637,10 +637,9 @@ pub fn main() {
unsafe {
let r = (1,2,3,true,false, Triple {x:5,y:4,z:3}, (12,));
let p = ptr::addr_of(&r) as *c_void;
let u = my_visitor(@Stuff {mut ptr1: p,
mut ptr2: p,
mut vals: ~[]
});
let u = my_visitor(@mut Stuff {ptr1: p,
ptr2: p,
vals: ~[]});
let v = ptr_visit_adaptor(Inner {inner: u});
let td = get_tydesc_for(r);
unsafe { error!("tydesc sz: %u, align: %u",

View File

@ -10,7 +10,7 @@
// xfail-test
use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor};
enum my_visitor = @{ mut types: ~[str] };
enum my_visitor = @mut { types: ~[str] };
impl TyVisitor for my_visitor {
fn visit_bot() -> bool {
@ -141,7 +141,7 @@ fn visit_ty<T>(v: TyVisitor) {
}
pub fn main() {
let v = my_visitor(@{mut types: ~[]});
let v = my_visitor(@mut {types: ~[]});
let vv = v as TyVisitor;
visit_ty::<bool>(vv);

View File

@ -37,7 +37,7 @@ fn r(v: *int) -> r {
enum t = Node;
struct Node {
mut next: Option<@t>,
next: Option<@mut t>,
r: r
}
@ -50,8 +50,8 @@ pub fn main() {
let i2p = cast::reinterpret_cast(&i2);
cast::forget(i2);
let x1 = @t(Node{
mut next: None,
let mut x1 = @mut t(Node{
next: None,
r: {
let rs = r(i1p);
debug!("r = %x",
@ -60,11 +60,11 @@ pub fn main() {
});
debug!("x1 = %x, x1.r = %x",
cast::reinterpret_cast::<@t, uint>(&x1),
cast::reinterpret_cast::<@mut t, uint>(&x1),
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x1.r))));
let x2 = @t(Node{
mut next: None,
let mut x2 = @mut t(Node{
next: None,
r: {
let rs = r(i2p);
debug!("r2 = %x",
@ -74,7 +74,7 @@ pub fn main() {
});
debug!("x2 = %x, x2.r = %x",
cast::reinterpret_cast::<@t, uint>(&x2),
cast::reinterpret_cast::<@mut t, uint>(&x2),
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x2.r))));
x1.next = Some(x2);

View File

@ -37,7 +37,7 @@ fn r(v: U) -> r {
enum t = Node;
struct Node {
mut next: Option<@t>,
next: Option<@mut t>,
r: r
}
@ -53,12 +53,12 @@ pub fn main() {
let u1 = U {a: 0xB, b: 0xC, c: i1p};
let u2 = U {a: 0xB, b: 0xC, c: i2p};
let x1 = @t(Node {
mut next: None,
let x1 = @mut t(Node {
next: None,
r: r(u1)
});
let x2 = @t(Node {
mut next: None,
let x2 = @mut t(Node {
next: None,
r: r(u2)
});
x1.next = Some(x2);

View File

@ -46,7 +46,7 @@ fn r(v: U, w: int, _x: *int) -> R {
enum t = Node;
struct Node {
mut next: Option<@t>,
next: Option<@mut t>,
r: R
}
@ -62,12 +62,12 @@ pub fn main() {
let u1 = U {a: 0xB, b: 0xC, c: i1p};
let u2 = U {a: 0xB, b: 0xC, c: i2p};
let x1 = @t(Node{
mut next: None,
let x1 = @mut t(Node{
next: None,
r: r(u1, 42, i1p)
});
let x2 = @t(Node{
mut next: None,
let x2 = @mut t(Node{
next: None,
r: r(u2, 42, i2p)
});
x1.next = Some(x2);

View File

@ -1,3 +1,6 @@
// xfail-test
// Weird borrow check bug
// 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.
@ -10,20 +13,20 @@
// Test cyclic detector when using trait instances.
enum Tree = @TreeR;
enum Tree = @mut TreeR;
struct TreeR {
mut left: Option<Tree>,
mut right: Option<Tree>,
left: Option<Tree>,
right: Option<Tree>,
val: to_str
}
trait to_str {
fn to_str() -> ~str;
fn to_str(&self) -> ~str;
}
impl<T:to_str> to_str for Option<T> {
fn to_str() -> ~str {
match self {
fn to_str(&self) -> ~str {
match *self {
None => { ~"none" }
Some(ref t) => { ~"some(" + t.to_str() + ~")" }
}
@ -31,26 +34,26 @@ impl<T:to_str> to_str for Option<T> {
}
impl to_str for int {
fn to_str() -> ~str { int::str(self) }
fn to_str(&self) -> ~str { int::str(*self) }
}
impl to_str for Tree {
fn to_str() -> ~str {
fn to_str(&self) -> ~str {
let l = self.left, r = self.right;
fmt!("[%s, %s, %s]", self.val.to_str(),
l.to_str(), r.to_str())
let val = &self.val;
fmt!("[%s, %s, %s]", val.to_str(), l.to_str(), r.to_str())
}
}
fn foo<T:to_str>(x: T) -> ~str { x.to_str() }
pub fn main() {
let t1 = Tree(@TreeR{mut left: None,
mut right: None,
val: 1 as to_str });
let t2 = Tree(@TreeR{mut left: Some(t1),
mut right: Some(t1),
val: 2 as to_str });
let t1 = Tree(@mut TreeR{left: None,
right: None,
val: 1 as to_str });
let t2 = Tree(@mut TreeR{left: Some(t1),
right: Some(t1),
val: 2 as to_str });
let expected = ~"[2, some([1, none, none]), some([1, none, none])]";
assert t2.to_str() == expected;
assert foo(t2 as to_str) == expected;

View File

@ -12,12 +12,12 @@
// -*- rust -*-
struct Point {x: int, y: int, mut z: int}
struct Point {x: int, y: int, z: int}
fn f(p: &mut Point) { p.z = 13; }
pub fn main() {
let mut x: Point = Point {x: 10, y: 11, mut z: 12};
let mut x: Point = Point {x: 10, y: 11, z: 12};
f(&mut x);
assert (x.z == 13);
}