From f63efdc2100ff28e2a42600641835e7bd8bde591 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 25 Feb 2013 14:04:32 -0800 Subject: [PATCH] test: De-~mut the test suite. rs=demuting --- src/test/bench/msgsend-ring-mutex-arcs.rs | 17 ++++++--------- src/test/bench/msgsend-ring-pipes.rs | 20 +++++++----------- src/test/bench/msgsend-ring-rw-arcs.rs | 17 ++++++--------- .../bench/task-perf-jargon-metal-smoke.rs | 8 ++++--- .../compile-fail/mutable-huh-variance-deep.rs | 4 ++-- .../mutable-huh-variance-unique.rs | 21 ------------------- src/test/compile-fail/no-send-res-ports.rs | 7 ++++--- src/test/compile-fail/unique-mut.rs | 14 ------------- .../run-pass/borrowck-preserve-box-in-uniq.rs | 2 +- src/test/run-pass/explicit-self-closures.rs | 3 --- src/test/run-pass/intrinsic-atomics.rs | 2 +- src/test/run-pass/issue-2718.rs | 14 ++++++------- src/test/run-pass/pipe-pingpong-bounded.rs | 19 ++++++++--------- src/test/run-pass/pipe-pingpong-proto.rs | 19 ++++++++--------- src/test/run-pass/pure-sum.rs | 4 ++-- src/test/run-pass/rcvr-borrowed-to-region.rs | 2 +- src/test/run-pass/task-killjoin-rsrc.rs | 7 +++---- src/test/run-pass/unique-assign-copy.rs | 2 +- src/test/run-pass/unique-decl-init-copy.rs | 2 +- src/test/run-pass/unique-in-vec-copy.rs | 2 +- src/test/run-pass/unique-mutable.rs | 2 +- 21 files changed, 67 insertions(+), 121 deletions(-) delete mode 100644 src/test/compile-fail/mutable-huh-variance-unique.rs delete mode 100644 src/test/compile-fail/unique-mut.rs diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 9b6fee5e23bc..22045007134a 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -87,17 +87,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); - let new_future = do future::spawn() || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); + let new_future = do future::spawn() { + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-pipes.rs b/src/test/bench/msgsend-ring-pipes.rs index 0f7c41f5997a..dfe5c6de832c 100644 --- a/src/test/bench/msgsend-ring-pipes.rs +++ b/src/test/bench/msgsend-ring-pipes.rs @@ -17,11 +17,12 @@ // This version uses automatically compiled channel contracts. extern mod std; + +use core::cell::Cell; +use core::pipes::recv; use std::time; use std::future; -use core::pipes::recv; - proto! ring ( num:send { num(uint) -> num @@ -80,17 +81,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = ring::init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); let new_future = do future::spawn || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index eaae8370d6b8..98c0129918a4 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -87,17 +87,12 @@ fn main() { for uint::range(1u, num_tasks) |i| { //error!("spawning %?", i); let (new_chan, num_port) = init(); - let num_chan2 = ~mut None; - *num_chan2 <-> num_chan; - let num_port = ~mut Some(num_port); - let new_future = do future::spawn || { - let mut num_chan = None; - num_chan <-> *num_chan2; - let mut num_port1 = None; - num_port1 <-> *num_port; - thread_ring(i, msg_per_task, - option::unwrap(num_chan), - option::unwrap(num_port1)) + let num_chan2 = Cell(num_chan); + let num_port = Cell(num_port); + let new_future = do future::spawn { + let num_chan = num_chan2.take(); + let num_port1 = num_port.take(); + thread_ring(i, msg_per_task, num_chan, num_port1) }; futures.push(new_future); num_chan = Some(new_chan); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 49a06fd491cd..9bdc5aae3f28 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -17,13 +17,15 @@ // // The filename is a song reference; google it in quotes. +use core::cell::Cell; + fn child_generation(gens_left: uint, -c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - let c = ~mut Some(c); - do task::spawn_supervised || { - let c = option::swap_unwrap(c); + let c = Cell(c); + do task::spawn_supervised { + let c = c.take(); if gens_left & 1 == 1 { task::yield(); // shake things up a bit } diff --git a/src/test/compile-fail/mutable-huh-variance-deep.rs b/src/test/compile-fail/mutable-huh-variance-deep.rs index 4f0c6d7a4c87..51d5a6177f6a 100644 --- a/src/test/compile-fail/mutable-huh-variance-deep.rs +++ b/src/test/compile-fail/mutable-huh-variance-deep.rs @@ -11,9 +11,9 @@ // error-pattern: mismatched types fn main() { - let v = ~[mut @mut ~mut ~[0]]; + let v = @[mut @mut @mut @[0]]; - fn f(&&v: ~[mut @mut ~mut ~[const int]]) { + fn f(&&v: @[mut @mut @mut @[const int]]) { } f(v); diff --git a/src/test/compile-fail/mutable-huh-variance-unique.rs b/src/test/compile-fail/mutable-huh-variance-unique.rs deleted file mode 100644 index f2188911346e..000000000000 --- a/src/test/compile-fail/mutable-huh-variance-unique.rs +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index 4954bbfa09d0..0d7e2d2377c2 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::cell::Cell; + struct Port(@T); fn main() { @@ -25,11 +27,10 @@ fn foo(x: Port<()>) -> foo { } } - let x = ~mut Some(foo(Port(@()))); + let x = Cell(foo(Port(@()))); do task::spawn { - let mut y = None; - *x <-> y; //~ ERROR value has non-owned type + let y = x.take(); //~ ERROR value has non-owned type log(error, y); } } diff --git a/src/test/compile-fail/unique-mut.rs b/src/test/compile-fail/unique-mut.rs deleted file mode 100644 index a3a197505a34..000000000000 --- a/src/test/compile-fail/unique-mut.rs +++ /dev/null @@ -1,14 +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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//error-pattern:mismatched types -fn main() { - let i: ~int = ~mut 0; -} diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs index 9724717f2d58..b11a5356f698 100644 --- a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs +++ b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs @@ -20,7 +20,7 @@ fn borrow(x: &int, f: fn(x: &int)) { struct F { f: ~int } pub fn main() { - let mut x = ~mut @F{f: ~3}; + let mut x = ~@F{f: ~3}; do borrow(x.f) |b_x| { assert *b_x == 3; assert ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)); diff --git a/src/test/run-pass/explicit-self-closures.rs b/src/test/run-pass/explicit-self-closures.rs index 4c12b6ad47c2..d40b2f72ae8b 100644 --- a/src/test/run-pass/explicit-self-closures.rs +++ b/src/test/run-pass/explicit-self-closures.rs @@ -21,9 +21,6 @@ fn set_many(&mut self, xs: &[uint]) { fn set_many2(@mut self, xs: &[uint]) { for xs.each |x| { self.x = *x; } } - fn set_many3(~mut self, xs: &[uint]) { - for xs.each |x| { self.x = *x; } - } } pub fn main() {} diff --git a/src/test/run-pass/intrinsic-atomics.rs b/src/test/run-pass/intrinsic-atomics.rs index eb10a51c0bd6..7d5bf65dad7c 100644 --- a/src/test/run-pass/intrinsic-atomics.rs +++ b/src/test/run-pass/intrinsic-atomics.rs @@ -29,7 +29,7 @@ pub fn main() { unsafe { - let x = ~mut 1; + let mut x = ~1; assert rusti::atomic_cxchg(x, 1, 2) == 1; assert *x == 2; diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 249d1c21376b..b97ebb04f716 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -318,18 +318,16 @@ pub fn main() { // Commented out because of option::get error let (client_, server_) = pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); + let client_ = Cell(client_); + let server_ = Cell(server_); task::spawn {|client_| - let mut client__ = none; - *client_ <-> client__; - client(option::unwrap(client__)); + let client__ = client_.take(); + client(client__); }; task::spawn {|server_| - let mut server_ˊ = none; - *server_ <-> server_ˊ; - server(option::unwrap(server_ˊ)); + let server__ = server_.take(); + server(server_ˊ); }; */ } diff --git a/src/test/run-pass/pipe-pingpong-bounded.rs b/src/test/run-pass/pipe-pingpong-bounded.rs index 2ada6df76a6a..23f2bc10046b 100644 --- a/src/test/run-pass/pipe-pingpong-bounded.rs +++ b/src/test/run-pass/pipe-pingpong-bounded.rs @@ -14,6 +14,7 @@ // experiment with what code the compiler should generate for bounded // protocols. +use core::cell::Cell; // This was generated initially by the pipe compiler, but it's been // modified in hopefully straightforward ways. @@ -111,16 +112,14 @@ pub fn server(-chan: ::pingpong::server::ping) { pub fn main() { let (client_, server_) = ::pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); - do task::spawn || { - let mut client__ = None; - *client_ <-> client__; - test::client(option::unwrap(client__)); + let client_ = Cell(client_); + let server_ = Cell(server_); + do task::spawn { + let client__ = client_.take(); + test::client(client__); }; - do task::spawn || { - let mut server_ˊ = None; - *server_ <-> server_ˊ; - test::server(option::unwrap(server_ˊ)); + do task::spawn { + let server__ = server_.take(); + test::server(server_ˊ); }; } diff --git a/src/test/run-pass/pipe-pingpong-proto.rs b/src/test/run-pass/pipe-pingpong-proto.rs index 050ff76ef9b7..a4a1c562bcaf 100644 --- a/src/test/run-pass/pipe-pingpong-proto.rs +++ b/src/test/run-pass/pipe-pingpong-proto.rs @@ -12,6 +12,7 @@ // An example to make sure the protocol parsing syntax extension works. +use core::cell::Cell; use core::option; proto! pingpong ( @@ -49,17 +50,15 @@ pub fn server(-chan: ::pingpong::server::ping) { pub fn main() { let (client_, server_) = pingpong::init(); - let client_ = ~mut Some(client_); - let server_ = ~mut Some(server_); + let client_ = Cell(client_); + let server_ = Cell(server_); - do task::spawn || { - let mut client__ = None; - *client_ <-> client__; - test::client(option::unwrap(client__)); + do task::spawn { + let client__ = client_.take(); + test::client(client__); }; - do task::spawn || { - let mut server_ˊ = None; - *server_ <-> server_ˊ; - test::server(option::unwrap(server_ˊ)); + do task::spawn { + let server__ = server_.take(); + test::server(server_ˊ); }; } diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index f4c92c869e46..cac6b4ef3493 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -20,7 +20,7 @@ } pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = ~mut 0; + let mut i = 0u, sum0 = ~0; while i < v.len() { *sum0 += v[i]; i += 1u; @@ -40,7 +40,7 @@ struct F { f: T } pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { - let mut i = 0u, sum0 = F {f: ~mut 0}; + let mut i = 0u, sum0 = F {f: ~0}; while i < v.len() { *sum0.f += v[i]; i += 1u; diff --git a/src/test/run-pass/rcvr-borrowed-to-region.rs b/src/test/run-pass/rcvr-borrowed-to-region.rs index 61cb473bf8fb..7011f5ba1add 100644 --- a/src/test/run-pass/rcvr-borrowed-to-region.rs +++ b/src/test/run-pass/rcvr-borrowed-to-region.rs @@ -31,7 +31,7 @@ pub fn main() { debug!("y=%d", y); assert y == 6; - let x = ~mut 6; + let mut x = ~6; let y = x.get(); debug!("y=%d", y); assert y == 6; diff --git a/src/test/run-pass/task-killjoin-rsrc.rs b/src/test/run-pass/task-killjoin-rsrc.rs index b90c39ab34e5..991025a1ad28 100644 --- a/src/test/run-pass/task-killjoin-rsrc.rs +++ b/src/test/run-pass/task-killjoin-rsrc.rs @@ -13,6 +13,7 @@ // A port of task-killjoin to use a class with a dtor to manage // the join. +use core::cell::Cell; use core::comm::*; struct notify { @@ -49,11 +50,9 @@ fn wrapper(c: Chan, f: fn()) { *b = true; } let (p, c) = stream(); - let c = ~mut Some(c); + let c = Cell(c); do task::spawn_unlinked { - let mut cc = None; - *c <-> cc; - let ccc = option::unwrap(cc); + let ccc = c.take(); wrapper(ccc, f) } p diff --git a/src/test/run-pass/unique-assign-copy.rs b/src/test/run-pass/unique-assign-copy.rs index 4723356dcd0c..1bb04aef2868 100644 --- a/src/test/run-pass/unique-assign-copy.rs +++ b/src/test/run-pass/unique-assign-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 1; + let mut i = ~1; // Should be a copy let mut j; j = copy i; diff --git a/src/test/run-pass/unique-decl-init-copy.rs b/src/test/run-pass/unique-decl-init-copy.rs index 628eb7265a5c..a0b7fc336e25 100644 --- a/src/test/run-pass/unique-decl-init-copy.rs +++ b/src/test/run-pass/unique-decl-init-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 1; + let mut i = ~1; // Should be a copy let j = copy i; *i = 2; diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 54ea0258c7c6..ac8796674abb 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let a = ~[~mut 10]; + let mut a = ~[~10]; let b = copy a; assert *a[0] == 10; diff --git a/src/test/run-pass/unique-mutable.rs b/src/test/run-pass/unique-mutable.rs index c52d3b563ac5..8784dbeb0af4 100644 --- a/src/test/run-pass/unique-mutable.rs +++ b/src/test/run-pass/unique-mutable.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let i = ~mut 0; + let mut i = ~0; *i = 1; assert *i == 1; }