1
Fork 0

Make moves explicit in core tests

This commit is contained in:
Tim Chevalier 2012-09-18 22:35:28 -07:00
parent 2d7d12b902
commit 30a62793fa
22 changed files with 178 additions and 146 deletions

View file

@ -122,9 +122,9 @@ pub mod tests {
pub fn test_transmute() {
unsafe {
let x = @1;
let x: *int = transmute(x);
let x: *int = transmute(move x);
assert *x == 1;
let _x: @int = transmute(x);
let _x: @int = transmute(move x);
}
}

View file

@ -142,7 +142,7 @@ pub unsafe fn annihilate() {
assert (*box).header.prev == null();
debug!("freeing box: %x", box as uint);
rt_free(transmute(box));
rt_free(transmute(move box));
}
}

View file

@ -301,7 +301,7 @@ pub mod rt {
unsafe { str::unshift_char(&mut s, ' ') };
}
}
return unsafe { pad(cv, s, PadSigned) };
return unsafe { pad(cv, move s, PadSigned) };
}
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
@ -313,7 +313,7 @@ pub mod rt {
TyBits => uint_to_str_prec(u, 2u, prec),
TyOctal => uint_to_str_prec(u, 8u, prec)
};
return unsafe { pad(cv, rs, PadUnsigned) };
return unsafe { pad(cv, move rs, PadUnsigned) };
}
pub pure fn conv_bool(cv: Conv, b: bool) -> ~str {
let s = if b { ~"true" } else { ~"false" };
@ -323,7 +323,7 @@ pub mod rt {
}
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
let mut s = str::from_char(c);
return unsafe { pad(cv, s, PadNozero) };
return unsafe { pad(cv, move s, PadNozero) };
}
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
@ -336,7 +336,7 @@ pub mod rt {
s.to_unique()
}
};
return unsafe { pad(cv, unpadded, PadNozero) };
return unsafe { pad(cv, move unpadded, PadNozero) };
}
pub pure fn conv_float(cv: Conv, f: float) -> ~str {
let (to_str, digits) = match cv.precision {
@ -351,7 +351,7 @@ pub mod rt {
s = ~" " + s;
}
}
return unsafe { pad(cv, s, PadFloat) };
return unsafe { pad(cv, move s, PadFloat) };
}
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
let s = sys::log_str(v);
@ -411,14 +411,14 @@ pub mod rt {
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
let mut s = move s; // sadtimes
let uwidth : uint = match cv.width {
CountImplied => return s,
CountImplied => return (move s),
CountIs(width) => {
// FIXME: width should probably be uint (see Issue #1996)
width as uint
}
};
let strlen = str::char_len(s);
if uwidth <= strlen { return s; }
if uwidth <= strlen { return (move s); }
let mut padchar = ' ';
let diff = uwidth - strlen;
if have_flag(cv.flags, flag_left_justify) {

View file

@ -179,8 +179,8 @@ pub mod test {
#[test]
pub fn test_from_port() {
let (po, ch) = future_pipe::init();
future_pipe::server::completed(ch, ~"whale");
let f = from_port(po);
future_pipe::server::completed(move ch, ~"whale");
let f = from_port(move po);
assert get(&f) == ~"whale";
}
@ -238,7 +238,7 @@ pub mod test {
pub fn test_sendable_future() {
let expected = ~"schlorf";
let f = do spawn |copy expected| { copy expected };
do task::spawn {
do task::spawn |move f, move expected| {
let actual = get(&f);
assert actual == expected;
}

View file

@ -438,7 +438,7 @@ pub fn test_siphash() {
for vec::each(*r) |b| {
s += uint::to_str(*b as uint, 16u);
}
return s;
move s
}
while t < 64 {

View file

@ -737,7 +737,7 @@ pub fn BytesWriter() -> BytesWriter {
pub fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
let wr = @BytesWriter();
f(wr as Writer);
wr.buf.check_out(|buf| buf)
wr.buf.check_out(|buf| move buf)
}
pub fn with_str_writer(f: fn(Writer)) -> ~str {
@ -747,7 +747,7 @@ pub fn with_str_writer(f: fn(Writer)) -> ~str {
v.push(0);
assert str::is_utf8(v);
unsafe { move ::cast::transmute(v) }
unsafe { move ::cast::transmute(move v) }
}
// Utility functions

View file

@ -24,7 +24,7 @@ struct Data<T> {
pub type Mut<T> = Data<T>;
pub fn Mut<T>(t: T) -> Mut<T> {
Data {value: t, mode: ReadOnly}
Data {value: move t, mode: ReadOnly}
}
pub fn unwrap<T>(m: Mut<T>) -> T {
@ -32,7 +32,7 @@ pub fn unwrap<T>(m: Mut<T>) -> T {
// is in use, as that would be a move from a borrowed value.
assert (m.mode as uint) == (ReadOnly as uint);
let Data {value: move value, mode: _} = move m;
return value;
move value
}
impl<T> Data<T> {

View file

@ -120,7 +120,7 @@ pub pure fn chain<T, U>(opt: Option<T>,
*/
match move opt {
Some(move t) => f(t),
Some(move t) => f(move t),
None => None
}
}
@ -294,7 +294,7 @@ impl<T: Copy> Option<T> {
*
* Fails if the value equals `none`
*/
pure fn expect(reason: ~str) -> T { expect(&self, reason) }
pure fn expect(reason: ~str) -> T { expect(&self, move reason) }
/// Applies a function zero or more times until the result is none.
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
}
@ -324,8 +324,8 @@ impl<T: Eq> Option<T> : Eq {
fn test_unwrap_ptr() {
let x = ~0;
let addr_x = ptr::addr_of(&(*x));
let opt = Some(x);
let y = unwrap(opt);
let opt = Some(move x);
let y = unwrap(move opt);
let addr_y = ptr::addr_of(&(*y));
assert addr_x == addr_y;
}
@ -356,8 +356,8 @@ fn test_unwrap_resource() {
let i = @mut 0;
{
let x = R(i);
let opt = Some(x);
let _y = unwrap(opt);
let opt = Some(move x);
let _y = unwrap(move opt);
}
assert *i == 1;
}

View file

@ -739,7 +739,7 @@ unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
for uint::range(0, argc as uint) |i| {
vec::push(&mut args, str::raw::from_c_str(*argv.offset(i)));
}
return args;
move args
}
/**
@ -903,7 +903,7 @@ mod tests {
let rng: rand::Rng = rand::Rng();
let n = ~"TEST" + rng.gen_str(10u);
assert getenv(n).is_none();
n
move n
}
#[test]
@ -937,7 +937,7 @@ mod tests {
let n = make_rand_name();
setenv(n, s);
log(debug, s);
assert getenv(n) == option::Some(s);
assert getenv(n) == option::Some(move s);
}
#[test]
@ -963,7 +963,7 @@ mod tests {
// MingW seems to set some funky environment variables like
// "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned
// from env() but not visible from getenv().
assert v2.is_none() || v2 == option::Some(v);
assert v2.is_none() || v2 == option::Some(move v);
}
}
@ -976,7 +976,7 @@ mod tests {
assert !vec::contains(e, &(copy n, ~"VALUE"));
e = env();
assert vec::contains(e, &(n, ~"VALUE"));
assert vec::contains(e, &(move n, ~"VALUE"));
}
#[test]

View file

@ -96,7 +96,7 @@ impl PosixPath : GenericPath {
let mut components = str::split_nonempty(s, |c| c == '/');
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
return PosixPath { is_absolute: is_absolute,
components: components }
components: move components }
}
pure fn dirname() -> ~str {
@ -192,7 +192,7 @@ impl PosixPath : GenericPath {
Some(ref f) => ~[copy *f]
};
return PosixPath { is_absolute: false,
components: cs }
components: move cs }
}
pure fn push_rel(other: &PosixPath) -> PosixPath {
@ -208,7 +208,8 @@ impl PosixPath : GenericPath {
|c| windows::is_sep(c as u8));
unsafe { v.push_all_move(move ss); }
}
PosixPath { components: move v, ..self }
PosixPath { is_absolute: self.is_absolute,
components: move v }
}
pure fn push(s: &str) -> PosixPath {
@ -223,13 +224,18 @@ impl PosixPath : GenericPath {
if cs.len() != 0 {
unsafe { cs.pop(); }
}
return PosixPath { components: move cs, ..self }
return PosixPath {
is_absolute: self.is_absolute,
components: move cs
}
//..self }
}
pure fn normalize() -> PosixPath {
return PosixPath {
components: normalize(self.components),
..self
is_absolute: self.is_absolute,
components: normalize(self.components)
// ..self
}
}
}
@ -286,10 +292,10 @@ impl WindowsPath : GenericPath {
let mut components =
str::split_nonempty(rest, |c| windows::is_sep(c as u8));
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
return WindowsPath { host: host,
device: device,
return WindowsPath { host: move host,
device: move device,
is_absolute: is_absolute,
components: components }
components: move components }
}
pure fn dirname() -> ~str {
@ -386,7 +392,7 @@ impl WindowsPath : GenericPath {
return WindowsPath { host: None,
device: None,
is_absolute: false,
components: cs }
components: move cs }
}
pure fn push_rel(other: &WindowsPath) -> WindowsPath {
@ -402,7 +408,13 @@ impl WindowsPath : GenericPath {
|c| windows::is_sep(c as u8));
unsafe { v.push_all_move(move ss); }
}
return WindowsPath { components: move v, ..self }
// tedious, but as-is, we can't use ..self
return WindowsPath {
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute,
components: move v
}
}
pure fn push(s: &str) -> WindowsPath {
@ -417,13 +429,20 @@ impl WindowsPath : GenericPath {
if cs.len() != 0 {
unsafe { cs.pop(); }
}
return WindowsPath { components: move cs, ..self }
return WindowsPath {
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute,
components: move cs
}
}
pure fn normalize() -> WindowsPath {
return WindowsPath {
components: normalize(self.components),
..self
host: copy self.host,
device: copy self.device,
is_absolute: self.is_absolute,
components: normalize(self.components)
}
}
}

View file

@ -350,7 +350,8 @@ fn BufferResource<T: Send>(b: ~Buffer<T>) -> BufferResource<T> {
atomic_add_acq(&mut b.header.ref_count, 1);
BufferResource {
buffer: b
// tjc: ????
buffer: move b
}
}
@ -448,7 +449,12 @@ pub fn try_recv<T: Send, Tbuffer: Send>(p: RecvPacketBuffered<T, Tbuffer>)
let this = rustrt::rust_get_task();
rustrt::task_clear_event_reject(this);
rustrt::rust_task_ref(this);
debug!("blocked = %x this = %x", p.header.blocked_task as uint,
this as uint);
let old_task = swap_task(&mut p.header.blocked_task, this);
debug!("blocked = %x this = %x old_task = %x",
p.header.blocked_task as uint,
this as uint, old_task as uint);
assert old_task.is_null();
let mut first = true;
let mut count = SPIN_COUNT;
@ -1212,7 +1218,7 @@ pub mod test {
c1.send(~"abc");
match (p1, p2).select() {
match (move p1, move p2).select() {
Right(_) => fail,
_ => ()
}
@ -1224,8 +1230,8 @@ pub mod test {
pub fn test_oneshot() {
let (c, p) = oneshot::init();
oneshot::client::send(c, ());
oneshot::client::send(move c, ());
recv_one(p)
recv_one(move p)
}
}

View file

@ -374,7 +374,7 @@ pub unsafe fn unwrap_shared_mutable_state<T: Send>(rc: SharedMutableState<T>)
rc.data = ptr::null();
// Step 1 - drop our own reference.
let new_count = rustrt::rust_atomic_decrement(&mut ptr.count);
assert new_count >= 0;
// assert new_count >= 0;
if new_count == 0 {
// We were the last owner. Can unwrap immediately.
// Also we have to free the server endpoints.
@ -505,7 +505,7 @@ pub struct Exclusive<T: Send> { x: SharedMutableState<ExData<T>> }
pub fn exclusive<T:Send >(user_data: T) -> Exclusive<T> {
let data = ExData {
lock: LittleLock(), mut failed: false, mut data: user_data
lock: LittleLock(), mut failed: false, mut data: move user_data
};
Exclusive { x: unsafe { shared_mutable_state(move data) } }
}
@ -558,17 +558,17 @@ pub mod tests {
pub fn exclusive_arc() {
let mut futures = ~[];
let num_tasks = 10u;
let count = 10u;
let num_tasks = 10;
let count = 10;
let total = exclusive(~mut 0u);
let total = exclusive(~mut 0);
for uint::range(0u, num_tasks) |_i| {
for uint::range(0, num_tasks) |_i| {
let total = total.clone();
futures.push(future::spawn(|| {
for uint::range(0u, count) |_i| {
futures.push(future::spawn(|move total| {
for uint::range(0, count) |_i| {
do total.with |count| {
**count += 1u;
**count += 1;
}
}
}));
@ -587,7 +587,7 @@ pub mod tests {
// accesses will also fail.
let x = exclusive(1);
let x2 = x.clone();
do task::try {
do task::try |move x2| {
do x2.with |one| {
assert *one == 2;
}
@ -600,27 +600,28 @@ pub mod tests {
#[test]
pub fn exclusive_unwrap_basic() {
let x = exclusive(~~"hello");
assert unwrap_exclusive(x) == ~~"hello";
assert unwrap_exclusive(move x) == ~~"hello";
}
#[test]
pub fn exclusive_unwrap_contended() {
let x = exclusive(~~"hello");
let x2 = ~mut Some(x.clone());
do task::spawn {
do task::spawn |move x2| {
let x2 = option::swap_unwrap(x2);
do x2.with |_hello| { }
task::yield();
}
assert unwrap_exclusive(x) == ~~"hello";
assert unwrap_exclusive(move x) == ~~"hello";
// Now try the same thing, but with the child task blocking.
let x = exclusive(~~"hello");
let x2 = ~mut Some(x.clone());
let mut res = None;
do task::task().future_result(|+r| res = Some(r)).spawn {
do task::task().future_result(|+r| res = Some(move r)).spawn
|move x2| {
let x2 = option::swap_unwrap(x2);
assert unwrap_exclusive(x2) == ~~"hello";
assert unwrap_exclusive(move x2) == ~~"hello";
}
// Have to get rid of our reference before blocking.
{ let _x = move x; } // FIXME(#3161) util::ignore doesn't work here
@ -633,11 +634,12 @@ pub mod tests {
let x = exclusive(~~"hello");
let x2 = ~mut Some(x.clone());
let mut res = None;
do task::task().future_result(|+r| res = Some(r)).spawn {
do task::task().future_result(|+r| res = Some(move r)).spawn
|move x2| {
let x2 = option::swap_unwrap(x2);
assert unwrap_exclusive(x2) == ~~"hello";
assert unwrap_exclusive(move x2) == ~~"hello";
}
assert unwrap_exclusive(x) == ~~"hello";
assert unwrap_exclusive(move x) == ~~"hello";
let res = option::swap_unwrap(&mut res);
future::get(&res);
}
@ -656,7 +658,7 @@ pub mod tests {
for 10.times { task::yield(); } // try to let the unwrapper go
fail; // punt it awake from its deadlock
}
let _z = unwrap_exclusive(x);
let _z = unwrap_exclusive(move x);
do x2.with |_hello| { }
};
assert result.is_err();

View file

@ -156,7 +156,7 @@ impl ReprVisitor {
fn visit_ptr_inner(ptr: *c_void, inner: *TyDesc) -> bool {
let mut u = ReprVisitor(ptr, self.writer);
let v = reflect::MovePtrAdaptor(move u);
visit_tydesc(inner, v as @TyVisitor);
visit_tydesc(inner, (move v) as @TyVisitor);
true
}
@ -453,7 +453,7 @@ pub fn write_repr2<T>(writer: @Writer, object: &T) {
let tydesc = intrinsic::get_tydesc::<T>();
let mut u = ReprVisitor(ptr, writer);
let v = reflect::MovePtrAdaptor(move u);
visit_tydesc(tydesc, v as @TyVisitor)
visit_tydesc(tydesc, (move v) as @TyVisitor)
}
#[test]
@ -992,7 +992,7 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
unsafe {
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
let tydesc = sys::get_type_desc::<T>();
let tydesc = cast::transmute(tydesc);
let tydesc = cast::transmute(move tydesc);
let repr_printer = @ReprPrinter {
ptr: ptr,

View file

@ -106,7 +106,7 @@ pub pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>)
pub fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(t: T)
-> Result<U, V>) -> Result<U, V> {
match move res {
Ok(move t) => op(t),
Ok(move t) => op(move t),
Err(move e) => Err(e)
}
}

View file

@ -226,7 +226,7 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program {
fn ProgRes(r: ProgRepr) -> ProgRes {
ProgRes {
r: r
r: move r
}
}
@ -313,10 +313,10 @@ pub fn program_output(prog: &str, args: &[~str]) ->
let stream = comm::recv(p);
match stream {
(1, copy s) => {
outs = s;
outs = move s;
}
(2, copy s) => {
errs = s;
errs = move s;
}
(n, _) => {
fail(fmt!("program_output received an unexpected file \

View file

@ -185,8 +185,8 @@ pub mod linear {
debug!("insert fresh (%?->%?) at idx %?, hash %?",
k, v, idx, hash);
self.buckets[idx] = Some(Bucket {hash: hash,
key: k,
value: v});
key: move k,
value: move v});
self.size += 1;
true
}
@ -194,8 +194,8 @@ pub mod linear {
debug!("insert overwrite (%?->%?) at idx %?, hash %?",
k, v, idx, hash);
self.buckets[idx] = Some(Bucket {hash: hash,
key: k,
value: v});
key: move k,
value: move v});
false
}
}
@ -230,7 +230,7 @@ pub mod linear {
None => None,
Some(move bucket) => {
let Bucket { value: move value, _ } = move bucket;
Some(value)
Some(move value)
},
};
@ -243,7 +243,7 @@ pub mod linear {
}
self.size -= 1;
value
move value
}
@ -297,9 +297,9 @@ pub mod linear {
self.expand();
}
self.insert_internal(hash, k, v);
self.insert_internal(hash, move k, move v);
old_value
move old_value
}
fn consume(&mut self, f: fn(K, V)) {
@ -307,7 +307,7 @@ pub mod linear {
self.buckets <-> buckets;
self.size = 0;
do vec::consume(buckets) |_i, bucket| {
do vec::consume(move buckets) |_i, bucket| {
match move bucket {
None => { },
Some(move bucket) => {
@ -316,7 +316,7 @@ pub mod linear {
value: move value,
_
} = move bucket;
f(key, value)
f(move key, move value)
}
}
}

View file

@ -2562,23 +2562,23 @@ mod tests {
#[test]
fn test_unsafe_slice() {
unsafe {
assert ~"ab" == raw::slice_bytes(~"abc", 0u, 2u);
assert ~"bc" == raw::slice_bytes(~"abc", 1u, 3u);
assert ~"" == raw::slice_bytes(~"abc", 1u, 1u);
assert ~"ab" == raw::slice_bytes(~"abc", 0, 2);
assert ~"bc" == raw::slice_bytes(~"abc", 1, 3);
assert ~"" == raw::slice_bytes(~"abc", 1, 1);
fn a_million_letter_a() -> ~str {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(&mut rs, ~"aaaaaaaaaa"); i += 1; }
return rs;
move rs
}
fn half_a_million_letter_a() -> ~str {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(&mut rs, ~"aaaaa"); i += 1; }
return rs;
move rs
}
assert half_a_million_letter_a() ==
raw::slice_bytes(a_million_letter_a(), 0u, 500000u);
raw::slice_bytes(a_million_letter_a(), 0u, 500000);
}
}
@ -2664,16 +2664,16 @@ mod tests {
#[test]
fn test_slice() {
assert ~"ab" == slice(~"abc", 0u, 2u);
assert ~"bc" == slice(~"abc", 1u, 3u);
assert ~"" == slice(~"abc", 1u, 1u);
assert ~"\u65e5" == slice(~"\u65e5\u672c", 0u, 3u);
assert ~"ab" == slice(~"abc", 0, 2);
assert ~"bc" == slice(~"abc", 1, 3);
assert ~"" == slice(~"abc", 1, 1);
assert ~"\u65e5" == slice(~"\u65e5\u672c", 0, 3);
let data = ~"ประเทศไทย中华";
assert ~"" == slice(data, 0u, 3u);
assert ~"" == slice(data, 3u, 6u);
assert ~"" == slice(data, 3u, 3u);
assert ~"" == slice(data, 30u, 33u);
assert ~"" == slice(data, 0, 3);
assert ~"" == slice(data, 3, 6);
assert ~"" == slice(data, 3, 3);
assert ~"" == slice(data, 30, 33);
fn a_million_letter_X() -> ~str {
let mut i = 0;
@ -2682,13 +2682,13 @@ mod tests {
push_str(&mut rs, ~"华华华华华华华华华华");
i += 1;
}
return rs;
move rs
}
fn half_a_million_letter_X() -> ~str {
let mut i = 0;
let mut rs = ~"";
while i < 100000 { push_str(&mut rs, ~"华华华华华"); i += 1; }
return rs;
move rs
}
assert half_a_million_letter_X() ==
slice(a_million_letter_X(), 0u, 3u * 500000u);

View file

@ -153,7 +153,7 @@ pub mod tests {
assert f(20) == 30;
let original_closure: Closure = cast::transmute(f);
let original_closure: Closure = cast::transmute(move f);
let actual_function_pointer = original_closure.code;
let environment = original_closure.env;
@ -163,7 +163,7 @@ pub mod tests {
env: environment
};
let new_f: fn(int) -> int = cast::transmute(new_closure);
let new_f: fn(int) -> int = cast::transmute(move new_closure);
assert new_f(20) == 30;
}
}

View file

@ -424,7 +424,11 @@ impl TaskBuilder {
mut notify_chan: move notify_chan,
sched: self.opts.sched
},
gen_body: |body| { wrapper(prev_gen_body(move body)) },
// tjc: I think this is the line that gets miscompiled
// w/ last-use off, if we leave out the move prev_gen_body?
// that makes no sense, though...
gen_body: |move prev_gen_body,
body| { wrapper(prev_gen_body(move body)) },
can_not_copy: None,
.. *self.consume()
})
@ -931,7 +935,7 @@ fn test_add_wrapper() {
let ch = comm::Chan(&po);
let b0 = task();
let b1 = do b0.add_wrapper |body| {
fn~() {
fn~(move body) {
body();
comm::send(ch, ());
}
@ -944,14 +948,15 @@ fn test_add_wrapper() {
#[ignore(cfg(windows))]
fn test_future_result() {
let mut result = None;
do task().future_result(|+r| { result = Some(r); }).spawn { }
assert future::get(&option::unwrap(result)) == Success;
do task().future_result(|+r| { result = Some(move r); }).spawn { }
assert future::get(&option::unwrap(move result)) == Success;
result = None;
do task().future_result(|+r| { result = Some(r); }).unlinked().spawn {
do task().future_result(|+r|
{ result = Some(move r); }).unlinked().spawn {
fail;
}
assert future::get(&option::unwrap(result)) == Failure;
assert future::get(&option::unwrap(move result)) == Failure;
}
#[test] #[should_fail] #[ignore(cfg(windows))]
@ -981,7 +986,7 @@ fn test_spawn_conversation() {
let (recv_str, send_int) = do spawn_conversation |recv_int, send_str| {
let input = comm::recv(recv_int);
let output = int::str(input);
comm::send(send_str, output);
comm::send(send_str, move output);
};
comm::send(send_int, 1);
assert comm::recv(recv_str) == ~"1";
@ -1134,7 +1139,7 @@ fn avoid_copying_the_body(spawnfn: fn(v: fn~())) {
let x = ~1;
let x_in_parent = ptr::addr_of(&(*x)) as uint;
do spawnfn {
do spawnfn |move x| {
let x_in_child = ptr::addr_of(&(*x)) as uint;
comm::send(ch, x_in_child);
}
@ -1160,7 +1165,7 @@ fn test_avoid_copying_the_body_spawn_listener() {
#[test]
fn test_avoid_copying_the_body_task_spawn() {
do avoid_copying_the_body |f| {
do task().spawn {
do task().spawn |move f| {
f();
}
}
@ -1178,7 +1183,7 @@ fn test_avoid_copying_the_body_spawn_listener_1() {
#[test]
fn test_avoid_copying_the_body_try() {
do avoid_copying_the_body |f| {
do try {
do try |move f| {
f()
};
}
@ -1187,7 +1192,7 @@ fn test_avoid_copying_the_body_try() {
#[test]
fn test_avoid_copying_the_body_unlinked() {
do avoid_copying_the_body |f| {
do spawn_unlinked {
do spawn_unlinked |move f| {
f();
}
}
@ -1212,7 +1217,7 @@ fn test_unkillable() {
// We want to do this after failing
do spawn_unlinked {
for iter::repeat(10u) { yield() }
for iter::repeat(10) { yield() }
ch.send(());
}
@ -1226,12 +1231,12 @@ fn test_unkillable() {
unsafe {
do unkillable {
let p = ~0;
let pp: *uint = cast::transmute(p);
let pp: *uint = cast::transmute(move p);
// If we are killed here then the box will leak
po.recv();
let _p: ~int = cast::transmute(pp);
let _p: ~int = cast::transmute(move pp);
}
}
@ -1246,8 +1251,8 @@ fn test_unkillable_nested() {
let (ch, po) = pipes::stream();
// We want to do this after failing
do spawn_unlinked {
for iter::repeat(10u) { yield() }
do spawn_unlinked |move ch| {
for iter::repeat(10) { yield() }
ch.send(());
}
@ -1262,12 +1267,12 @@ fn test_unkillable_nested() {
do unkillable {
do unkillable {} // Here's the difference from the previous test.
let p = ~0;
let pp: *uint = cast::transmute(p);
let pp: *uint = cast::transmute(move p);
// If we are killed here then the box will leak
po.recv();
let _p: ~int = cast::transmute(pp);
let _p: ~int = cast::transmute(move pp);
}
}
@ -1311,7 +1316,7 @@ fn test_child_doesnt_ref_parent() {
fn test_sched_thread_per_core() {
let (chan, port) = pipes::stream();
do spawn_sched(ThreadPerCore) {
do spawn_sched(ThreadPerCore) |move chan| {
let cores = rt::rust_num_threads();
let reported_threads = rt::rust_sched_threads();
assert(cores as uint == reported_threads as uint);
@ -1325,7 +1330,7 @@ fn test_sched_thread_per_core() {
fn test_spawn_thread_on_demand() {
let (chan, port) = pipes::stream();
do spawn_sched(ManualThreads(2)) {
do spawn_sched(ManualThreads(2)) |move chan| {
let max_threads = rt::rust_sched_threads();
assert(max_threads as int == 2);
let running_threads = rt::rust_sched_current_nonlazy_threads();
@ -1333,7 +1338,7 @@ fn test_spawn_thread_on_demand() {
let (chan2, port2) = pipes::stream();
do spawn() {
do spawn() |move chan2| {
chan2.send(());
}

View file

@ -312,8 +312,8 @@ fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList,
TCB {
me: me,
tasks: tasks,
ancestors: ancestors,
tasks: move tasks,
ancestors: move ancestors,
is_main: is_main,
notifier: move notifier
}
@ -330,7 +330,7 @@ struct AutoNotify {
fn AutoNotify(chan: Chan<Notification>) -> AutoNotify {
AutoNotify {
notify_chan: chan,
notify_chan: move chan,
failed: true // Un-set above when taskgroup successfully made.
}
}
@ -652,7 +652,7 @@ fn test_spawn_raw_unsupervise() {
mut notify_chan: None,
.. default_task_opts()
};
do spawn_raw(opts) {
do spawn_raw(move opts) {
fail;
}
}
@ -667,7 +667,7 @@ fn test_spawn_raw_notify_success() {
notify_chan: Some(move notify_ch),
.. default_task_opts()
};
do spawn_raw(opts) |move task_ch| {
do spawn_raw(move opts) |move task_ch| {
task_ch.send(get_task());
}
let task_ = task_po.recv();
@ -683,10 +683,10 @@ fn test_spawn_raw_notify_failure() {
let opts = {
linked: false,
notify_chan: Some(notify_ch),
notify_chan: Some(move notify_ch),
.. default_task_opts()
};
do spawn_raw(opts) {
do spawn_raw(move opts) |move task_ch| {
task_ch.send(get_task());
fail;
}

View file

@ -100,7 +100,7 @@ mod tests {
let x = ~[(5, false)];
//FIXME #3387 assert x.eq(id(copy x));
let y = copy x;
assert x.eq(&id(y));
assert x.eq(&id(move y));
}
#[test]
fn test_swap() {

View file

@ -340,15 +340,15 @@ pub fn splitn<T: Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] {
*/
pub fn rsplit<T: Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] {
let ln = len(v);
if (ln == 0u) { return ~[] }
if (ln == 0) { return ~[] }
let mut end = ln;
let mut result = ~[];
while end > 0u {
match rposition_between(v, 0u, end, f) {
while end > 0 {
match rposition_between(v, 0, end, f) {
None => break,
Some(i) => {
result.push(slice(v, i + 1u, end));
result.push(slice(v, i + 1, end));
end = i;
}
}
@ -416,7 +416,7 @@ pub fn shift<T>(v: &mut ~[T]) -> T {
pub fn unshift<T>(v: &mut ~[T], x: T) {
let mut vv = ~[move x];
*v <-> vv;
v.push_all_move(vv);
v.push_all_move(move vv);
}
pub fn consume<T>(v: ~[T], f: fn(uint, v: T)) unsafe {
@ -433,7 +433,7 @@ pub fn consume<T>(v: ~[T], f: fn(uint, v: T)) unsafe {
}
pub fn consume_mut<T>(v: ~[mut T], f: fn(uint, v: T)) {
consume(vec::from_mut(v), f)
consume(vec::from_mut(move v), f)
}
/// Remove the last element from a vector and return it
@ -591,7 +591,7 @@ pub pure fn append_one<T>(lhs: ~[T], x: T) -> ~[T] {
#[inline(always)]
pure fn append_mut<T: Copy>(lhs: ~[mut T], rhs: &[const T]) -> ~[mut T] {
to_mut(append(from_mut(lhs), rhs))
to_mut(append(from_mut(move lhs), rhs))
}
/**
@ -1621,7 +1621,7 @@ impl<T> ~[T]: MutableVector<T> {
}
fn unshift(&mut self, x: T) {
unshift(self, x)
unshift(self, move x)
}
fn swap_remove(&mut self, index: uint) -> T {
@ -2208,7 +2208,7 @@ mod tests {
#[test]
fn test_dedup() {
fn case(a: ~[uint], b: ~[uint]) {
let mut v = a;
let mut v = move a;
v.dedup();
assert(v == b);
}
@ -2464,13 +2464,13 @@ mod tests {
let v1 = ~[1, 2, 3];
let v2 = ~[4, 5, 6];
let z1 = zip(v1, v2);
let z1 = zip(move v1, move v2);
assert ((1, 4) == z1[0]);
assert ((2, 5) == z1[1]);
assert ((3, 6) == z1[2]);
let (left, right) = unzip(z1);
let (left, right) = unzip(move z1);
assert ((1, 4) == (left[0], right[0]));
assert ((2, 5) == (left[1], right[1]));
@ -2768,7 +2768,7 @@ mod tests {
unsafe {
let x = ~[1, 2, 3];
let addr = raw::to_ptr(x);
let x_mut = to_mut(x);
let x_mut = to_mut(move x);
let addr_mut = raw::to_ptr(x_mut);
assert addr == addr_mut;
}
@ -2779,7 +2779,7 @@ mod tests {
unsafe {
let x = ~[mut 1, 2, 3];
let addr = raw::to_ptr(x);
let x_imm = from_mut(x);
let x_imm = from_mut(move x);
let addr_imm = raw::to_ptr(x_imm);
assert addr == addr_imm;
}
@ -2977,7 +2977,7 @@ mod tests {
fn test_consume_fail() {
let v = ~[(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do consume(v) |_i, _elt| {
do consume(move v) |_i, _elt| {
if i == 2 {
fail
}
@ -2991,7 +2991,7 @@ mod tests {
fn test_consume_mut_fail() {
let v = ~[mut (~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do consume_mut(v) |_i, _elt| {
do consume_mut(move v) |_i, _elt| {
if i == 2 {
fail
}
@ -3034,7 +3034,7 @@ mod tests {
fn test_map_consume_fail() {
let v = ~[(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do map_consume(v) |_elt| {
do map_consume(move v) |_elt| {
if i == 2 {
fail
}