Stop using the '<->' operator

This commit is contained in:
Alex Crichton 2013-05-06 00:42:54 -04:00
parent 7d22437ecd
commit 998fececd6
29 changed files with 214 additions and 296 deletions

View file

@ -14,6 +14,7 @@ extern mod std;
use std::time::precise_time_s;
use core::rand::RngUtil;
use core::util;
macro_rules! bench (
($id:ident) => (maybe_run_test(argv, stringify!($id).to_owned(), $id))
@ -115,7 +116,7 @@ fn vec_push_all() {
v.push_all(rv);
}
else {
v <-> rv;
util::swap(&mut v, &mut rv);
v.push_all(rv);
}
}

View file

@ -20,6 +20,7 @@ extern mod std;
use core::cell::Cell;
use core::pipes::recv;
use core::util;
use std::time;
use std::future;
@ -42,10 +43,8 @@ fn thread_ring(i: uint,
// Send/Receive lots of messages.
for uint::range(0, count) |j| {
//error!("task %?, iter %?", i, j);
let mut num_chan2 = None;
let mut num_port2 = None;
num_chan2 <-> num_chan;
num_port2 <-> num_port;
let num_chan2 = replace(&mut num_chan, None);
let num_port2 = replace(&mut num_port, None);
num_chan = Some(ring::client::num(num_chan2.unwrap(), i * j));
let port = num_port2.unwrap();
match recv(port) {

View file

@ -17,6 +17,7 @@ use core::hashmap::HashMap;
use core::io::ReaderUtil;
use core::comm::{stream, Port, Chan};
use core::cmp::Ord;
use core::util;
// given a map, print a sorted version of it
fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
@ -159,8 +160,7 @@ fn main() {
let mut from_child = ~[];
let to_child = vec::mapi(sizes, |ii, sz| {
let sz = *sz;
let mut stream = None;
stream <-> streams[ii];
let stream = util::replace(&mut streams[ii], None);
let (from_child_, to_parent_) = stream.unwrap();
from_child.push(from_child_);

View file

@ -1,28 +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 test1() {
let v: int;
let mut w: int;
v = 1; //~ NOTE prior assignment occurs here
w = 2;
v <-> w; //~ ERROR re-assignment of immutable variable
}
fn test2() {
let v: int;
let mut w: int;
v = 1; //~ NOTE prior assignment occurs here
w = 2;
w <-> v; //~ ERROR re-assignment of immutable variable
}
fn main() {
}

View file

@ -1,16 +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 = 3;
let y;
x <-> y; //~ ERROR use of possibly uninitialized variable: `y`
copy x;
}

View file

@ -87,7 +87,7 @@ fn f110() {
fn f120() {
let x = ~[~"hi", ~"ho"];
x[0] <-> x[1];
vec::swap(x, 0, 1);
touch(&x[0]);
touch(&x[1]);
}

View file

@ -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() {
5 <-> 3;
//~^ ERROR cannot assign
//~^^ ERROR cannot assign
}

View file

@ -8,14 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
struct Ints {sum: ~int, values: ~[int]}
fn add_int(x: &mut Ints, v: int) {
*x.sum += v;
let mut values = ~[];
x.values <-> values;
util::swap(&mut values, &mut x.values);
values.push(v);
x.values <-> values;
util::swap(&mut values, &mut x.values);
}
fn iter_ints(x: &Ints, f: &fn(x: &int) -> bool) -> bool {

View file

@ -10,8 +10,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
// tjc: I don't know why
pub mod pipes {
use core::util;
use core::cast::{forget, transmute};
pub struct Stuff<T> {
@ -104,8 +107,7 @@ pub mod pipes {
match old_state {
empty | blocked => { task::yield(); }
full => {
let mut payload = None;
payload <-> (*p).payload;
let payload = util::replace(&mut p.payload, None);
return Some(payload.unwrap())
}
terminated => {
@ -159,10 +161,9 @@ pub mod pipes {
fn finalize(&self) {
unsafe {
if self.p != None {
let mut p = None;
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
let p = util::replace(self_p, None);
sender_terminate(p.unwrap())
}
}
@ -171,9 +172,7 @@ pub mod pipes {
pub impl<T:Owned> send_packet<T> {
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
p.unwrap()
util::replace(&mut self.p, None).unwrap()
}
}
@ -192,10 +191,9 @@ pub mod pipes {
fn finalize(&self) {
unsafe {
if self.p != None {
let mut p = None;
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
let p = util::replace(self_p, None);
receiver_terminate(p.unwrap())
}
}
@ -204,9 +202,7 @@ pub mod pipes {
pub impl<T:Owned> recv_packet<T> {
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
p.unwrap()
util::replace(&mut self.p, None).unwrap()
}
}
@ -225,6 +221,7 @@ pub mod pipes {
pub mod pingpong {
use core::cast;
use core::ptr;
use core::util;
pub struct ping(::pipes::send_packet<pong>);
pub struct pong(::pipes::send_packet<ping>);

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
pub fn main() {
let mut x = 4;
@ -24,6 +26,6 @@ pub fn main() {
}
}
let mut y = 4;
y <-> x;
util::swap(&mut y, &mut x);
}
}

View file

@ -8,7 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
pub fn main() {
let mut x = 3; let mut y = 7;
x <-> y; assert!((x == 7)); assert!((y == 3));
util::swap(&mut x, &mut y);
assert!((x == 7)); assert!((y == 3));
}

View file

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn swap<T>(v: &mut [T], i: int, j: int) { v[i] <-> v[j]; }
use core::util;
pub fn main() {
let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6];
swap(a, 2, 4);
vec::swap(a, 2, 4);
assert!((a[2] == 4));
assert!((a[4] == 2));
let mut n = 42;
n <-> a[0];
util::swap(&mut n, &mut a[0]);
assert!((a[0] == 42));
assert!((n == 0));
}

View file

@ -10,6 +10,8 @@
// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same
use core::util;
pub fn main() {
let mut test = TestDescAndFn {
desc: TestDesc {
@ -22,7 +24,10 @@ pub fn main() {
}
fn do_swap(test: &mut TestDescAndFn) {
*test <-> *test;
unsafe {
util::swap_ptr(ptr::to_mut_unsafe_ptr(test),
ptr::to_mut_unsafe_ptr(test));
}
}
pub enum TestName {

View file

@ -8,10 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
pub fn main() {
let mut i = ~100;
let mut j = ~200;
i <-> j;
util::swap(&mut i, &mut j);
assert!(i == ~200);
assert!(j == ~100);
}

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::util;
// Just a grab bag of stuff that you wouldn't want to actually write.
fn strange() -> bool { let _x: bool = return true; }
@ -52,7 +54,7 @@ fn notsure() {
let mut _y = (_x = 0) == (_x = 0);
let mut _z = (_x = 0) < (_x = 0);
let _a = (_x += 0) == (_x = 0);
let _b = (_y <-> _z) == (_y <-> _z);
let _b = util::swap(&mut _y, &mut _z) == util::swap(&mut _y, &mut _z);
}
fn canttouchthis() -> uint {