Skip to content

Commit c3694d7

Browse files
committed
test: De-@mut the test suite
1 parent df13c64 commit c3694d7

File tree

72 files changed

+351
-837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+351
-837
lines changed

src/test/auxiliary/cci_nested_lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010

1111
#[feature(managed_boxes)];
1212

13+
use std::cell::RefCell;
14+
1315
pub struct Entry<A,B> {
1416
key: A,
1517
value: B
1618
}
1719

1820
pub struct alist<A,B> {
1921
eq_fn: extern "Rust" fn(A,A) -> bool,
20-
data: @mut ~[Entry<A,B>]
22+
data: @RefCell<~[Entry<A,B>]>,
2123
}
2224

2325
pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
24-
lst.data.push(Entry{key:k, value:v});
26+
let mut data = lst.data.borrow_mut();
27+
data.get().push(Entry{key:k, value:v});
2528
}
2629

2730
pub fn alist_get<A:Clone + 'static,
@@ -30,7 +33,8 @@ pub fn alist_get<A:Clone + 'static,
3033
k: A)
3134
-> B {
3235
let eq_fn = lst.eq_fn;
33-
for entry in lst.data.iter() {
36+
let data = lst.data.borrow();
37+
for entry in data.get().iter() {
3438
if eq_fn(entry.key.clone(), k.clone()) {
3539
return entry.value.clone();
3640
}
@@ -41,12 +45,18 @@ pub fn alist_get<A:Clone + 'static,
4145
#[inline]
4246
pub fn new_int_alist<B:'static>() -> alist<int, B> {
4347
fn eq_int(a: int, b: int) -> bool { a == b }
44-
return alist {eq_fn: eq_int, data: @mut ~[]};
48+
return alist {
49+
eq_fn: eq_int,
50+
data: @RefCell::new(~[]),
51+
};
4552
}
4653

4754
#[inline]
4855
pub fn new_int_alist_2<B:'static>() -> alist<int, B> {
4956
#[inline]
5057
fn eq_int(a: int, b: int) -> bool { a == b }
51-
return alist {eq_fn: eq_int, data: @mut ~[]};
58+
return alist {
59+
eq_fn: eq_int,
60+
data: @RefCell::new(~[]),
61+
};
5262
}

src/test/auxiliary/issue-2631-a.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
extern mod extra;
1616

17+
use std::cell::RefCell;
1718
use std::hashmap::HashMap;
1819

19-
pub type header_map = HashMap<~str, @mut ~[@~str]>;
20+
pub type header_map = HashMap<~str, @RefCell<~[@~str]>>;
2021

2122
// the unused ty param is necessary so this gets monomorphized
2223
pub fn request<T>(req: &header_map) {
23-
let _x = (*((**req.get(&~"METHOD")).clone())[0u]).clone();
24+
let _x = (*((**req.get(&~"METHOD")).clone()).get()[0u]).clone();
2425
}

src/test/bench/sudoku.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Sudoku {
8686
return Sudoku::new(g)
8787
}
8888
89-
pub fn write(&self, writer: @mut io::Writer) {
89+
pub fn write(&self, writer: &mut io::Writer) {
9090
for row in range(0u8, 9u8) {
9191
write!(writer, "{}", self.grid[row][0]);
9292
for col in range(1u8, 9u8) {
@@ -280,5 +280,5 @@ fn main() {
280280
Sudoku::read(BufferedReader::new(io::stdin()))
281281
};
282282
sudoku.solve();
283-
sudoku.write(@mut io::stdout() as @mut io::Writer);
283+
sudoku.write(&mut io::stdout());
284284
}

src/test/compile-fail/cast-immutable-mutable-trait.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/test/compile-fail/fn-variance-1.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[feature(managed_boxes)];
11+
fn takes_imm(x: &int) { }
1212

13-
fn takes_mut(x: @mut int) { }
14-
fn takes_imm(x: @int) { }
13+
fn takes_mut(x: &mut int) { }
1514

1615
fn apply<T>(t: T, f: |T|) {
1716
f(t)
1817
}
1918

2019
fn main() {
21-
apply(@3, takes_mut); //~ ERROR (values differ in mutability)
22-
apply(@3, takes_imm);
20+
apply(&3, takes_mut); //~ ERROR (values differ in mutability)
21+
apply(&3, takes_imm);
2322

24-
apply(@mut 3, takes_mut);
25-
apply(@mut 3, takes_imm); //~ ERROR (values differ in mutability)
23+
apply(&mut 3, takes_mut);
24+
apply(&mut 3, takes_imm); //~ ERROR (values differ in mutability)
2625
}

src/test/compile-fail/issue-10487.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@
1212

1313
static x: ~[int] = ~[123, 456]; //~ ERROR: cannot allocate vectors in constant expressions
1414
static y: @[int] = @[123, 456]; //~ ERROR: cannot allocate vectors in constant expressions
15-
static z: @mut [int] = @mut [123, 456]; //~ ERROR: cannot allocate vectors in constant expressions
1615

1716
fn main() {}

src/test/compile-fail/issue-2548.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212

1313
// A test case for #2548.
1414

15-
struct foo {
16-
x: @mut int,
17-
15+
use std::cell::Cell;
1816

17+
struct foo {
18+
x: @Cell<int>,
1919
}
2020

2121
#[unsafe_destructor]
2222
impl Drop for foo {
2323
fn drop(&mut self) {
2424
unsafe {
2525
println("Goodbye, World!");
26-
*self.x += 1;
26+
self.x.set(self.x.get() + 1);
2727
}
2828
}
2929
}
3030

31-
fn foo(x: @mut int) -> foo {
31+
fn foo(x: @Cell<int>) -> foo {
3232
foo { x: x }
3333
}
3434

3535
fn main() {
36-
let x = @mut 0;
36+
let x = @Cell::new(0);
3737

3838
{
3939
let mut res = foo(x);
@@ -43,5 +43,5 @@ fn main() {
4343
assert_eq!(v.len(), 2);
4444
}
4545

46-
assert_eq!(*x, 1);
46+
assert_eq!(x.get(), 1);
4747
}

src/test/compile-fail/issue-3668.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#[feature(managed_boxes)];
1212

13-
struct P { child: Option<@mut P> }
13+
struct P { child: Option<@P> }
1414
trait PTrait {
1515
fn getChildOption(&self) -> Option<@P>;
1616
}

src/test/compile-fail/kindck-destructor-owned.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#[feature(managed_boxes)];
22

33
struct Foo {
4-
f: @mut int,
4+
f: @int,
55
}
66

77
impl Drop for Foo { //~ ERROR cannot implement a destructor on a structure that does not satisfy Send
88
fn drop(&mut self) {
9-
*self.f = 10;
109
}
1110
}
1211

src/test/compile-fail/lub-in-args.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/test/compile-fail/object-pointer-types.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ trait Foo {
1515
fn borrowed_mut(&mut self);
1616

1717
fn managed(@self);
18-
fn managed_mut(@mut self);
1918

2019
fn owned(~self);
2120
}
@@ -24,39 +23,27 @@ fn borrowed_receiver(x: &Foo) {
2423
x.borrowed();
2524
x.borrowed_mut(); // See [1]
2625
x.managed(); //~ ERROR does not implement any method
27-
x.managed_mut(); //~ ERROR does not implement any method
2826
x.owned(); //~ ERROR does not implement any method
2927
}
3028

3129
fn borrowed_mut_receiver(x: &mut Foo) {
3230
x.borrowed();
3331
x.borrowed_mut();
3432
x.managed(); //~ ERROR does not implement any method
35-
x.managed_mut(); //~ ERROR does not implement any method
3633
x.owned(); //~ ERROR does not implement any method
3734
}
3835

3936
fn managed_receiver(x: @Foo) {
4037
x.borrowed();
4138
x.borrowed_mut(); // See [1]
4239
x.managed();
43-
x.managed_mut(); //~ ERROR does not implement any method
44-
x.owned(); //~ ERROR does not implement any method
45-
}
46-
47-
fn managed_mut_receiver(x: @mut Foo) {
48-
x.borrowed();
49-
x.borrowed_mut();
50-
x.managed(); //~ ERROR does not implement any method
51-
x.managed_mut();
5240
x.owned(); //~ ERROR does not implement any method
5341
}
5442

5543
fn owned_receiver(x: ~Foo) {
5644
x.borrowed();
5745
x.borrowed_mut(); // See [1]
5846
x.managed(); //~ ERROR does not implement any method
59-
x.managed_mut(); //~ ERROR does not implement any method
6047
x.owned();
6148
}
6249

src/test/compile-fail/pinned-deep-copy.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010

1111
#[feature(managed_boxes)];
1212

13+
use std::cell::Cell;
14+
1315
struct r {
14-
i: @mut int,
16+
i: @Cell<int>,
1517
}
1618

1719
#[unsafe_destructor]
1820
impl Drop for r {
1921
fn drop(&mut self) {
2022
unsafe {
21-
*(self.i) = *(self.i) + 1;
23+
self.i.set(self.i.get() + 1);
2224
}
2325
}
2426
}
2527

26-
fn r(i: @mut int) -> r {
28+
fn r(i: @Cell<int>) -> r {
2729
r {
2830
i: i
2931
}
@@ -34,7 +36,7 @@ struct A {
3436
}
3537

3638
fn main() {
37-
let i = @mut 0;
39+
let i = @Cell::new(0);
3840
{
3941
// Can't do this copy
4042
let x = ~~~A {y: r(i)};

src/test/compile-fail/regions-infer-invariance-due-to-mutability-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#[feature(managed_boxes)];
1212

1313
struct invariant<'a> {
14-
f: 'static |x: @mut &'a int|
14+
f: 'static |x: &mut &'a int|
1515
}
1616

1717
fn to_same_lifetime<'r>(bi: invariant<'r>) {

src/test/compile-fail/regions-infer-invariance-due-to-mutability-4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#[feature(managed_boxes)];
1212

1313
struct invariant<'a> {
14-
f: 'static || -> @mut &'a int
14+
f: 'static || -> &mut &'a int
1515
}
1616

1717
fn to_same_lifetime<'r>(bi: invariant<'r>) {

src/test/compile-fail/unique-vec-res.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
#[feature(managed_boxes)];
1212

13+
use std::cell::Cell;
14+
1315
struct r {
14-
i: @mut int,
16+
i: @Cell<int>,
1517
}
1618

1719
#[unsafe_destructor]
1820
impl Drop for r {
1921
fn drop(&mut self) {
2022
unsafe {
21-
*(self.i) = *(self.i) + 1;
23+
self.i.set(self.i.get() + 1);
2224
}
2325
}
2426
}
@@ -27,12 +29,12 @@ fn f<T>(_i: ~[T], _j: ~[T]) {
2729
}
2830

2931
fn main() {
30-
let i1 = @mut 0;
31-
let i2 = @mut 1;
32+
let i1 = @Cell::new(0);
33+
let i2 = @Cell::new(1);
3234
let r1 = ~[~r { i: i1 }];
3335
let r2 = ~[~r { i: i2 }];
3436
f(r1.clone(), r2.clone());
3537
//~^ ERROR failed to find an implementation of
36-
info!("{:?}", (r2, *i1));
37-
info!("{:?}", (r1, *i2));
38+
info!("{:?}", (r2, i1.get()));
39+
info!("{:?}", (r1, i2.get()));
3840
}

0 commit comments

Comments
 (0)