Make moves explicit in std tests

This commit is contained in:
Tim Chevalier 2012-09-18 22:35:42 -07:00
parent 30a62793fa
commit 90d06b80fd
11 changed files with 98 additions and 96 deletions

View file

@ -124,7 +124,7 @@ pub fn mutex_arc_with_condvars<T: Send>(user_data: T,
num_condvars: uint) -> MutexARC<T> {
let data =
MutexARCInner { lock: mutex_with_condvars(num_condvars),
failed: false, data: user_data };
failed: false, data: move user_data };
MutexARC { x: unsafe { shared_mutable_state(move data) } }
}
@ -258,7 +258,7 @@ pub fn rw_arc_with_condvars<T: Const Send>(user_data: T,
num_condvars: uint) -> RWARC<T> {
let data =
RWARCInner { lock: rwlock_with_condvars(num_condvars),
failed: false, data: user_data };
failed: false, data: move user_data };
RWARC { x: unsafe { shared_mutable_state(move data) }, cant_nest: () }
}
@ -448,7 +448,7 @@ mod tests {
let (c, p) = pipes::stream();
do task::spawn() {
do task::spawn() |move c| {
let p = pipes::PortSet();
c.send(p.chan());
@ -471,8 +471,8 @@ mod tests {
let arc = ~MutexARC(false);
let arc2 = ~arc.clone();
let (c,p) = pipes::oneshot();
let (c,p) = (~mut Some(c), ~mut Some(p));
do task::spawn {
let (c,p) = (~mut Some(move c), ~mut Some(move p));
do task::spawn |move arc2, move p| {
// wait until parent gets in
pipes::recv_one(option::swap_unwrap(p));
do arc2.access_cond |state, cond| {
@ -494,7 +494,7 @@ mod tests {
let arc2 = ~arc.clone();
let (c,p) = pipes::stream();
do task::spawn_unlinked {
do task::spawn_unlinked |move arc2, move p| {
let _ = p.recv();
do arc2.access_cond |one, cond| {
cond.signal();
@ -513,7 +513,7 @@ mod tests {
fn test_mutex_arc_poison() {
let arc = ~MutexARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.access |one| {
assert *one == 2;
}
@ -527,21 +527,21 @@ mod tests {
let arc = MutexARC(1);
let arc2 = ~(&arc).clone();
let (c,p) = pipes::stream();
do task::spawn {
do task::spawn |move c, move arc2| {
do arc2.access |one| {
c.send(());
assert *one == 2;
}
}
let _ = p.recv();
let one = unwrap_mutex_arc(arc);
let one = unwrap_mutex_arc(move arc);
assert one == 1;
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_rw_arc_poison_wr() {
let arc = ~RWARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.write |one| {
assert *one == 2;
}
@ -554,7 +554,7 @@ mod tests {
fn test_rw_arc_poison_ww() {
let arc = ~RWARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.write |one| {
assert *one == 2;
}
@ -567,7 +567,7 @@ mod tests {
fn test_rw_arc_poison_dw() {
let arc = ~RWARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.write_downgrade |write_mode| {
do (&write_mode).write |one| {
assert *one == 2;
@ -582,7 +582,7 @@ mod tests {
fn test_rw_arc_no_poison_rr() {
let arc = ~RWARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.read |one| {
assert *one == 2;
}
@ -595,7 +595,7 @@ mod tests {
fn test_rw_arc_no_poison_rw() {
let arc = ~RWARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.read |one| {
assert *one == 2;
}
@ -608,9 +608,9 @@ mod tests {
fn test_rw_arc_no_poison_dr() {
let arc = ~RWARC(1);
let arc2 = ~arc.clone();
do task::try {
do task::try |move arc2| {
do arc2.write_downgrade |write_mode| {
let read_mode = arc2.downgrade(write_mode);
let read_mode = arc2.downgrade(move write_mode);
do (&read_mode).read |one| {
assert *one == 2;
}
@ -626,7 +626,7 @@ mod tests {
let arc2 = ~arc.clone();
let (c,p) = pipes::stream();
do task::spawn {
do task::spawn |move arc2, move c| {
do arc2.write |num| {
for 10.times {
let tmp = *num;
@ -642,7 +642,8 @@ mod tests {
let mut children = ~[];
for 5.times {
let arc3 = ~arc.clone();
do task::task().future_result(|+r| children.push(r)).spawn {
do task::task().future_result(|+r| children.push(move r)).spawn
|move arc3| {
do arc3.read |num| {
assert *num >= 0;
}
@ -670,9 +671,9 @@ mod tests {
let mut reader_convos = ~[];
for 10.times {
let ((rc1,rp1),(rc2,rp2)) = (pipes::stream(),pipes::stream());
reader_convos.push((rc1,rp2));
reader_convos.push((move rc1, move rp2));
let arcn = ~arc.clone();
do task::spawn {
do task::spawn |move rp1, move rc2, move arcn| {
rp1.recv(); // wait for downgrader to give go-ahead
do arcn.read |state| {
assert *state == 31337;
@ -684,7 +685,7 @@ mod tests {
// Writer task
let arc2 = ~arc.clone();
let ((wc1,wp1),(wc2,wp2)) = (pipes::stream(),pipes::stream());
do task::spawn {
do task::spawn |move arc2, move wc2, move wp1| {
wp1.recv();
do arc2.write_cond |state, cond| {
assert *state == 0;
@ -717,7 +718,7 @@ mod tests {
}
}
}
let read_mode = arc.downgrade(write_mode);
let read_mode = arc.downgrade(move write_mode);
do (&read_mode).read |state| {
// complete handshake with other readers
for vec::each(reader_convos) |x| {

View file

@ -96,7 +96,7 @@ struct BigBitv {
}
fn BigBitv(storage: ~[mut uint]) -> BigBitv {
BigBitv {storage: storage}
BigBitv {storage: move storage}
}
/**
@ -223,7 +223,7 @@ pub fn Bitv (nbits: uint, init: bool) -> Bitv {
let s = to_mut(from_elem(nelems, elem));
Big(~BigBitv(move s))
};
Bitv {rep: rep, nbits: nbits}
Bitv {rep: move rep, nbits: nbits}
}
priv impl Bitv {
@ -301,7 +301,7 @@ impl Bitv {
let st = to_mut(from_elem(self.nbits / uint_bits + 1, 0));
let len = st.len();
for uint::range(0, len) |i| { st[i] = b.storage[i]; };
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: st})}
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: move st})}
}
}
}

View file

@ -57,7 +57,7 @@ fn test_basic() {
let value = value_cell.take();
assert value == ~10;
assert value_cell.is_empty();
value_cell.put_back(value);
value_cell.put_back(move value);
assert !value_cell.is_empty();
}

View file

@ -52,12 +52,12 @@ pub fn DuplexStream<T: Send, U: Send>()
let (c2, p1) = pipes::stream();
let (c1, p2) = pipes::stream();
(DuplexStream {
chan: c1,
port: p1
chan: move c1,
port: move p1
},
DuplexStream {
chan: c2,
port: p2
chan: move c2,
port: move p2
})
}

View file

@ -329,8 +329,8 @@ pub fn Parser(rdr: io::Reader) -> Parser {
Parser {
rdr: rdr,
ch: rdr.read_char(),
line: 1u,
col: 1u,
line: 1,
col: 1,
}
}
@ -342,7 +342,7 @@ pub impl Parser {
self.parse_whitespace();
// Make sure there is no trailing characters.
if self.eof() {
Ok(value)
Ok(move value)
} else {
self.error(~"trailing characters")
}
@ -610,12 +610,12 @@ priv impl Parser {
if self.ch == ']' {
self.bump();
return Ok(List(values));
return Ok(List(move values));
}
loop {
match move self.parse_value() {
Ok(move v) => values.push(v),
Ok(move v) => values.push(move v),
Err(move e) => return Err(e)
}
@ -626,7 +626,7 @@ priv impl Parser {
match self.ch {
',' => self.bump(),
']' => { self.bump(); return Ok(List(values)); }
']' => { self.bump(); return Ok(List(move values)); }
_ => return self.error(~"expected `,` or `]`")
}
};
@ -640,7 +640,7 @@ priv impl Parser {
if self.ch == '}' {
self.bump();
return Ok(Object(values));
return Ok(Object(move values));
}
while !self.eof() {
@ -664,14 +664,14 @@ priv impl Parser {
self.bump();
match move self.parse_value() {
Ok(move value) => { values.insert(key, value); }
Ok(move value) => { values.insert(key, move value); }
Err(move e) => return Err(e)
}
self.parse_whitespace();
match self.ch {
',' => self.bump(),
'}' => { self.bump(); return Ok(Object(values)); }
'}' => { self.bump(); return Ok(Object(move values)); }
_ => {
if self.eof() { break; }
return self.error(~"expected `,` or `}`");
@ -703,7 +703,7 @@ pub struct Deserializer {
pub fn Deserializer(rdr: io::Reader) -> Result<Deserializer, Error> {
match move from_reader(rdr) {
Ok(move json) => {
let des = Deserializer { json: json, stack: ~[] };
let des = Deserializer { json: move json, stack: ~[] };
Ok(move des)
}
Err(move e) => Err(e)
@ -819,7 +819,7 @@ pub impl Deserializer: serialization::Deserializer {
};
let res = f(len);
self.pop();
res
move res
}
fn read_managed_vec<T>(&self, f: fn(uint) -> T) -> T {
@ -830,7 +830,7 @@ pub impl Deserializer: serialization::Deserializer {
};
let res = f(len);
self.pop();
res
move res
}
fn read_vec_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
@ -851,14 +851,14 @@ pub impl Deserializer: serialization::Deserializer {
debug!("read_rec()");
let value = f();
self.pop();
value
move value
}
fn read_struct<T>(&self, _name: &str, f: fn() -> T) -> T {
debug!("read_struct()");
let value = f();
self.pop();
value
move value
}
fn read_field<T>(&self, name: &str, idx: uint, f: fn() -> T) -> T {
@ -891,7 +891,7 @@ pub impl Deserializer: serialization::Deserializer {
debug!("read_tup(len=%u)", len);
let value = f();
self.pop();
value
move value
}
fn read_tup_elt<T>(&self, idx: uint, f: fn() -> T) -> T {
@ -1183,11 +1183,11 @@ mod tests {
for items.each |item| {
match *item {
(copy key, copy value) => { d.insert(key, value); },
(copy key, copy value) => { d.insert(key, move value); },
}
};
Object(d)
Object(move d)
}
#[test]

View file

@ -128,7 +128,7 @@ pub mod v4 {
*/
pub fn parse_addr(ip: &str) -> IpAddr {
match try_parse_addr(ip) {
result::Ok(copy addr) => addr,
result::Ok(move addr) => move addr,
result::Err(ref err_data) => fail err_data.err_msg
}
}
@ -214,7 +214,7 @@ pub mod v6 {
*/
pub fn parse_addr(ip: &str) -> IpAddr {
match try_parse_addr(ip) {
result::Ok(copy addr) => addr,
result::Ok(move addr) => move addr,
result::Err(copy err_data) => fail err_data.err_msg
}
}
@ -353,7 +353,7 @@ mod test {
}
// note really sure how to realiably test/assert
// this.. mostly just wanting to see it work, atm.
let results = result::unwrap(ga_result);
let results = result::unwrap(move ga_result);
log(debug, fmt!("test_get_addr: Number of results for %s: %?",
localhost_name, vec::len(results)));
for vec::each(results) |r| {
@ -366,7 +366,7 @@ mod test {
}
// at least one result.. this is going to vary from system
// to system, based on stuff like the contents of /etc/hosts
assert vec::len(results) > 0;
assert !results.is_empty();
}
#[test]
#[ignore(reason = "valgrind says it's leaky")]

View file

@ -562,7 +562,8 @@ pub fn listen(host_ip: ip::IpAddr, port: uint, backlog: uint,
new_connect_cb: fn~(TcpNewConnection,
comm::Chan<Option<TcpErrData>>))
-> result::Result<(), TcpListenErrData> unsafe {
do listen_common(move host_ip, port, backlog, iotask, on_establish_cb)
do listen_common(move host_ip, port, backlog, iotask,
move on_establish_cb)
// on_connect_cb
|move new_connect_cb, handle| unsafe {
let server_data_ptr = uv::ll::get_data_for_uv_handle(handle)

View file

@ -250,7 +250,7 @@ mod test_qsort {
sort::quick_sort(|x, y| { int::le(*x, *y) }, names);
let immut_names = vec::from_mut(names);
let immut_names = vec::from_mut(move names);
let pairs = vec::zip(expected, immut_names);
for vec::each(pairs) |p| {

View file

@ -25,7 +25,7 @@ struct Waitqueue { head: pipes::Port<SignalEnd>,
fn new_waitqueue() -> Waitqueue {
let (block_tail, block_head) = pipes::stream();
Waitqueue { head: block_head, tail: block_tail }
Waitqueue { head: move block_head, tail: move block_tail }
}
// Signals one live task from the queue.
@ -71,7 +71,7 @@ enum Sem<Q: Send> = Exclusive<SemInner<Q>>;
#[doc(hidden)]
fn new_sem<Q: Send>(count: int, q: Q) -> Sem<Q> {
Sem(exclusive(SemInner {
mut count: count, waiters: new_waitqueue(), blocked: q }))
mut count: count, waiters: new_waitqueue(), blocked: move q }))
}
#[doc(hidden)]
fn new_sem_and_signal(count: int, num_condvars: uint)
@ -686,7 +686,7 @@ mod tests {
fn test_sem_as_mutex() {
let s = ~semaphore(1);
let s2 = ~s.clone();
do task::spawn {
do task::spawn |move s2| {
do s2.access {
for 5.times { task::yield(); }
}
@ -701,7 +701,7 @@ mod tests {
let (c,p) = pipes::stream();
let s = ~semaphore(0);
let s2 = ~s.clone();
do task::spawn {
do task::spawn |move s2, move c| {
s2.acquire();
c.send(());
}
@ -713,7 +713,7 @@ mod tests {
let (c,p) = pipes::stream();
let s = ~semaphore(0);
let s2 = ~s.clone();
do task::spawn {
do task::spawn |move s2, move p| {
for 5.times { task::yield(); }
s2.release();
let _ = p.recv();
@ -729,7 +729,7 @@ mod tests {
let s2 = ~s.clone();
let (c1,p1) = pipes::stream();
let (c2,p2) = pipes::stream();
do task::spawn {
do task::spawn |move s2, move c1, move p2| {
do s2.access {
let _ = p2.recv();
c1.send(());
@ -748,10 +748,10 @@ mod tests {
let s = ~semaphore(1);
let s2 = ~s.clone();
let (c,p) = pipes::stream();
let child_data = ~mut Some((s2,c));
let child_data = ~mut Some((move s2, move c));
do s.access {
let (s2,c) = option::swap_unwrap(child_data);
do task::spawn {
do task::spawn |move c, move s2| {
c.send(());
do s2.access { }
c.send(());
@ -774,7 +774,7 @@ mod tests {
let m2 = ~m.clone();
let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate));
do task::spawn {
do task::spawn |move m2, move c| {
let sharedstate: &mut int =
unsafe { cast::reinterpret_cast(&ptr) };
access_shared(sharedstate, m2, 10);
@ -803,7 +803,7 @@ mod tests {
// Child wakes up parent
do m.lock_cond |cond| {
let m2 = ~m.clone();
do task::spawn {
do task::spawn |move m2| {
do m2.lock_cond |cond| {
let woken = cond.signal();
assert woken;
@ -814,7 +814,7 @@ mod tests {
// Parent wakes up child
let (chan,port) = pipes::stream();
let m3 = ~m.clone();
do task::spawn {
do task::spawn |move chan, move m3| {
do m3.lock_cond |cond| {
chan.send(());
cond.wait();
@ -836,8 +836,8 @@ mod tests {
for num_waiters.times {
let mi = ~m.clone();
let (chan, port) = pipes::stream();
ports.push(port);
do task::spawn {
ports.push(move port);
do task::spawn |move chan, move mi| {
do mi.lock_cond |cond| {
chan.send(());
cond.wait();
@ -867,7 +867,7 @@ mod tests {
fn test_mutex_cond_no_waiter() {
let m = ~Mutex();
let m2 = ~m.clone();
do task::try {
do task::try |move m| {
do m.lock_cond |_x| { }
};
do m2.lock_cond |cond| {
@ -880,7 +880,7 @@ mod tests {
let m = ~Mutex();
let m2 = ~m.clone();
let result: result::Result<(),()> = do task::try {
let result: result::Result<(),()> = do task::try |move m2| {
do m2.lock {
fail;
}
@ -896,9 +896,9 @@ mod tests {
let m = ~Mutex();
let m2 = ~m.clone();
let result: result::Result<(),()> = do task::try {
let result: result::Result<(),()> = do task::try |move m2| {
let (c,p) = pipes::stream();
do task::spawn { // linked
do task::spawn |move p| { // linked
let _ = p.recv(); // wait for sibling to get in the mutex
task::yield();
fail;
@ -921,19 +921,19 @@ mod tests {
let m2 = ~m.clone();
let (c,p) = pipes::stream();
let result: result::Result<(),()> = do task::try {
let result: result::Result<(),()> = do task::try |move c, move m2| {
let mut sibling_convos = ~[];
for 2.times {
let (c,p) = pipes::stream();
let c = ~mut Some(c);
sibling_convos.push(p);
let c = ~mut Some(move c);
sibling_convos.push(move p);
let mi = ~m2.clone();
// spawn sibling task
do task::spawn { // linked
do task::spawn |move mi, move c| { // linked
do mi.lock_cond |cond| {
let c = option::swap_unwrap(c);
c.send(()); // tell sibling to go ahead
let _z = SendOnFailure(c);
let _z = SendOnFailure(move c);
cond.wait(); // block forever
}
}
@ -942,7 +942,7 @@ mod tests {
let _ = p.recv(); // wait for sibling to get in the mutex
}
do m2.lock { }
c.send(sibling_convos); // let parent wait on all children
c.send(move sibling_convos); // let parent wait on all children
fail;
};
assert result.is_err();
@ -959,7 +959,7 @@ mod tests {
fn SendOnFailure(c: pipes::Chan<()>) -> SendOnFailure {
SendOnFailure {
c: c
c: move c
}
}
}
@ -969,7 +969,7 @@ mod tests {
let m = ~Mutex();
do m.lock_cond |cond| {
let m2 = ~m.clone();
do task::spawn {
do task::spawn |move m2| {
do m2.lock_cond |cond| {
cond.signal_on(0);
}
@ -983,7 +983,7 @@ mod tests {
let m = ~mutex_with_condvars(2);
let m2 = ~m.clone();
let (c,p) = pipes::stream();
do task::spawn {
do task::spawn |move m2, move c| {
do m2.lock_cond |cond| {
c.send(());
cond.wait_on(1);
@ -1032,7 +1032,7 @@ mod tests {
},
DowngradeRead =>
do x.write_downgrade |mode| {
let mode = x.downgrade(mode);
let mode = x.downgrade(move mode);
(&mode).read(blk);
},
}
@ -1046,7 +1046,7 @@ mod tests {
let x2 = ~x.clone();
let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate));
do task::spawn {
do task::spawn |move c, move x2| {
let sharedstate: &mut int =
unsafe { cast::reinterpret_cast(&ptr) };
access_shared(sharedstate, x2, mode1, 10);
@ -1089,7 +1089,7 @@ mod tests {
let x2 = ~x.clone();
let (c1,p1) = pipes::stream();
let (c2,p2) = pipes::stream();
do task::spawn {
do task::spawn |move c1, move x2, move p2| {
if !make_mode2_go_first {
let _ = p2.recv(); // parent sends to us once it locks, or ...
}
@ -1126,10 +1126,10 @@ mod tests {
// Tests that downgrade can unlock the lock in both modes
let x = ~RWlock();
do lock_rwlock_in_mode(x, Downgrade) { }
test_rwlock_handshake(x, Read, Read, false);
test_rwlock_handshake(move x, Read, Read, false);
let y = ~RWlock();
do lock_rwlock_in_mode(y, DowngradeRead) { }
test_rwlock_exclusion(y, Write, Write);
test_rwlock_exclusion(move y, Write, Write);
}
#[test]
fn test_rwlock_read_recursive() {
@ -1144,7 +1144,7 @@ mod tests {
// Child wakes up parent
do x.write_cond |cond| {
let x2 = ~x.clone();
do task::spawn {
do task::spawn |move x2| {
do x2.write_cond |cond| {
let woken = cond.signal();
assert woken;
@ -1155,7 +1155,7 @@ mod tests {
// Parent wakes up child
let (chan,port) = pipes::stream();
let x3 = ~x.clone();
do task::spawn {
do task::spawn |move x3, move chan| {
do x3.write_cond |cond| {
chan.send(());
cond.wait();
@ -1190,8 +1190,8 @@ mod tests {
for num_waiters.times {
let xi = ~x.clone();
let (chan, port) = pipes::stream();
ports.push(port);
do task::spawn {
ports.push(move port);
do task::spawn |move chan, move xi| {
do lock_cond(xi, dg1) |cond| {
chan.send(());
cond.wait();
@ -1226,7 +1226,7 @@ mod tests {
let x = ~RWlock();
let x2 = ~x.clone();
let result: result::Result<(),()> = do task::try {
let result: result::Result<(),()> = do task::try |move x2| {
do lock_rwlock_in_mode(x2, mode1) {
fail;
}
@ -1264,7 +1264,7 @@ mod tests {
let x = ~RWlock();
let y = ~RWlock();
do x.write_downgrade |xwrite| {
let mut xopt = Some(xwrite);
let mut xopt = Some(move xwrite);
do y.write_downgrade |_ywrite| {
y.downgrade(option::swap_unwrap(&mut xopt));
error!("oops, y.downgrade(x) should have failed!");

View file

@ -130,7 +130,7 @@ pub fn run_tests_console(opts: &TestOpts,
st.failed += 1u;
write_failed(st.out, st.use_color);
st.out.write_line(~"");
st.failures.push(test);
st.failures.push(move test);
}
TrIgnored => {
st.ignored += 1u;
@ -249,7 +249,7 @@ fn should_sort_failures_before_printing_them() {
mut passed: 0u,
mut failed: 0u,
mut ignored: 0u,
mut failures: ~[test_b, test_a]};
mut failures: ~[move test_b, move test_a]};
print_failures(st);
};
@ -534,9 +534,9 @@ mod tests {
for vec::each(names) |name| {
let test = {name: *name, testfn: copy testfn, ignore: false,
should_fail: false};
tests.push(test);
tests.push(move test);
}
tests
move tests
};
let filtered = filter_tests(&opts, tests);
@ -549,7 +549,7 @@ mod tests {
~"test::parse_ignored_flag",
~"test::sort_tests"];
let pairs = vec::zip(expected, filtered);
let pairs = vec::zip(expected, move filtered);
for vec::each(pairs) |p| {
match *p {

View file

@ -55,7 +55,7 @@ pub fn delayed_send<T: Send>(iotask: IoTask,
// delayed_send_cb has been processed by libuv
core::comm::recv(timer_done_po);
// notify the caller immediately
core::comm::send(ch, copy(val));
core::comm::send(ch, move(val));
// uv_close for this timer has been processed
core::comm::recv(timer_done_po);
};