Mostly rote conversion of proc() to move|| (and occasionally Thunk::new)

This commit is contained in:
Niko Matsakis 2014-11-26 08:12:18 -05:00
parent 394f6846b8
commit 5c3d398919
207 changed files with 693 additions and 694 deletions

View File

@ -9,7 +9,7 @@
// except according to those terms.
#![crate_type = "bin"]
#![feature(phase, slicing_syntax, globs)]
#![feature(phase, slicing_syntax, globs, unboxed_closures)]
#![deny(warnings)]
@ -23,6 +23,7 @@ use std::os;
use std::io;
use std::io::fs;
use std::str::FromStr;
use std::thunk::{Thunk};
use getopts::{optopt, optflag, reqopt};
use common::Config;
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
@ -369,16 +370,16 @@ pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_string();
test::DynTestFn(proc() {
test::DynTestFn(Thunk::new(move || {
runtest::run(config, testfile)
})
}))
}
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_string();
test::DynMetricFn(proc(mm) {
test::DynMetricFn(box move |: mm: &mut test::MetricMap| {
runtest::run_metrics(config, testfile, mm)
})
}

View File

@ -445,7 +445,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
loop {
//waiting 1 second for gdbserver start
timer::sleep(Duration::milliseconds(1000));
let result = task::try(proc() {
let result = task::try(move || {
tcp::TcpStream::connect("127.0.0.1:5039").unwrap();
});
if result.is_err() {

View File

@ -29,10 +29,11 @@ with a closure argument. `spawn` executes the closure in the new task.
fn print_message() { println!("I am running in a different task!"); }
spawn(print_message);
// Alternatively, use a `proc` expression instead of a named function.
// The `proc` expression evaluates to an (unnamed) proc.
// That proc will call `println!(...)` when the spawned task runs.
spawn(proc() println!("I am also running in a different task!") );
// Alternatively, use a `move ||` expression instead of a named function.
// `||` expressions evaluate to an unnamed closures. The `move` keyword
// indicates that the closure should take ownership of any variables it
// touches.
spawn(move || println!("I am also running in a different task!"));
```
In Rust, a task is not a concept that appears in the language semantics.
@ -40,11 +41,13 @@ Instead, Rust's type system provides all the tools necessary to implement safe
concurrency: particularly, ownership. The language leaves the implementation
details to the standard library.
The `spawn` function has a very simple type signature: `fn spawn(f: proc():
Send)`. Because it accepts only procs, and procs contain only owned data,
`spawn` can safely move the entire proc and all its associated state into an
entirely different task for execution. Like any closure, the function passed to
`spawn` may capture an environment that it carries across tasks.
The `spawn` function has the type signature: `fn
spawn<F:FnOnce()+Send>(f: F)`. This indicates that it takes as
argument a closure (of type `F`) that it will run exactly once. This
closure is limited to capturing `Send`-able data form its environment
(that is, data which is deeply owned). Limiting the closure to `Send`
ensures that `spawn` can safely move the entire closure and all its
associated state into an entirely different task for execution.
```{rust}
# use std::task::spawn;
@ -52,8 +55,11 @@ entirely different task for execution. Like any closure, the function passed to
// Generate some state locally
let child_task_number = generate_task_number();
spawn(proc() {
// Capture it in the remote task
spawn(move || {
// Capture it in the remote task. The `move` keyword indicates
// that this closure should move `child_task_number` into its
// environment, rather than capturing a reference into the
// enclosing stack frame.
println!("I am child number {}", child_task_number);
});
```
@ -74,7 +80,7 @@ example of calculating two results concurrently:
let (tx, rx): (Sender<int>, Receiver<int>) = channel();
spawn(proc() {
spawn(move || {
let result = some_expensive_computation();
tx.send(result);
});
@ -102,7 +108,7 @@ task.
# use std::task::spawn;
# fn some_expensive_computation() -> int { 42 }
# let (tx, rx) = channel();
spawn(proc() {
spawn(move || {
let result = some_expensive_computation();
tx.send(result);
});
@ -135,13 +141,13 @@ results across a number of tasks? The following program is ill-typed:
# fn some_expensive_computation() -> int { 42 }
let (tx, rx) = channel();
spawn(proc() {
spawn(move || {
tx.send(some_expensive_computation());
});
// ERROR! The previous spawn statement already owns the sender,
// so the compiler will not allow it to be captured again
spawn(proc() {
spawn(move || {
tx.send(some_expensive_computation());
});
```
@ -154,7 +160,7 @@ let (tx, rx) = channel();
for init_val in range(0u, 3) {
// Create a new channel handle to distribute to the child task
let child_tx = tx.clone();
spawn(proc() {
spawn(move || {
child_tx.send(some_expensive_computation(init_val));
});
}
@ -179,7 +185,7 @@ reference, written with multiple streams, it might look like the example below.
// Create a vector of ports, one for each child task
let rxs = Vec::from_fn(3, |init_val| {
let (tx, rx) = channel();
spawn(proc() {
spawn(move || {
tx.send(some_expensive_computation(init_val));
});
rx
@ -207,7 +213,7 @@ fn fib(n: u64) -> u64 {
12586269025
}
let mut delayed_fib = Future::spawn(proc() fib(50));
let mut delayed_fib = Future::spawn(move || fib(50));
make_a_sandwich();
println!("fib(50) = {}", delayed_fib.get())
# }
@ -236,7 +242,7 @@ fn partial_sum(start: uint) -> f64 {
}
fn main() {
let mut futures = Vec::from_fn(200, |ind| Future::spawn( proc() { partial_sum(ind) }));
let mut futures = Vec::from_fn(200, |ind| Future::spawn(move || partial_sum(ind)));
let mut final_res = 0f64;
for ft in futures.iter_mut() {
@ -278,7 +284,7 @@ fn main() {
for num in range(1u, 10) {
let task_numbers = numbers_arc.clone();
spawn(proc() {
spawn(move || {
println!("{}-norm = {}", num, pnorm(task_numbers.as_slice(), num));
});
}
@ -312,7 +318,7 @@ if it were local.
# let numbers_arc = Arc::new(numbers);
# let num = 4;
let task_numbers = numbers_arc.clone();
spawn(proc() {
spawn(move || {
// Capture task_numbers and use it as if it was the underlying vector
println!("{}-norm = {}", num, pnorm(task_numbers.as_slice(), num));
});
@ -344,7 +350,7 @@ result with an `int` field (representing a successful result) or an `Err` result
# use std::task;
# fn some_condition() -> bool { false }
# fn calculate_result() -> int { 0 }
let result: Result<int, Box<std::any::Any + Send>> = task::try(proc() {
let result: Result<int, Box<std::any::Any + Send>> = task::try(move || {
if some_condition() {
calculate_result()
} else {

View File

@ -210,11 +210,11 @@ that one can still write things like `#[deriving(Eq)]`).
# // what's actually being documented.
# fn fib(n: int) { n + 2 }
spawn(proc() { fib(200); })
spawn(move || { fib(200); })
```
~~~
The documentation online would look like `spawn(proc() { fib(200); })`, but when
The documentation online would look like `spawn(move || { fib(200); })`, but when
testing this code, the `fib` function will be included (so it can compile).
## Running tests (advanced)

View File

@ -46,7 +46,7 @@ use heap::deallocate;
/// for _ in range(0u, 10) {
/// let child_numbers = shared_numbers.clone();
///
/// spawn(proc() {
/// spawn(move || {
/// let local_numbers = child_numbers.as_slice();
///
/// // Work with the local numbers
@ -358,7 +358,7 @@ mod tests {
let (tx, rx) = channel();
task::spawn(proc() {
task::spawn(move || {
let arc_v: Arc<Vec<int>> = rx.recv();
assert_eq!((*arc_v)[3], 4);
});

View File

@ -1133,7 +1133,7 @@ mod tests {
#[test]
fn test_send() {
let n = list_from(&[1i,2,3]);
spawn(proc() {
spawn(move || {
check_links(&n);
let a: &[_] = &[&1,&2,&3];
assert_eq!(a, n.iter().collect::<Vec<&int>>());

View File

@ -21,7 +21,7 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(phase)]
#![feature(phase, unboxed_closures)]
#[cfg(test)] #[phase(plugin, link)] extern crate log;
@ -59,7 +59,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
&mut outsz,
flags);
if !res.is_null() {
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res)))
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, move|:| libc::free(res)))
} else {
None
}
@ -84,7 +84,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
&mut outsz,
flags);
if !res.is_null() {
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res)))
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, move|:| libc::free(res)))
} else {
None
}

View File

@ -165,7 +165,7 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules)]
#![feature(macro_rules, unboxed_closures)]
#![deny(missing_docs)]
extern crate regex;
@ -422,7 +422,7 @@ fn init() {
DIRECTIVES = mem::transmute(box directives);
// Schedule the cleanup for the globals for when the runtime exits.
rt::at_exit(proc() {
rt::at_exit(move |:| {
assert!(!DIRECTIVES.is_null());
let _directives: Box<Vec<directive::LogDirective>> =
mem::transmute(DIRECTIVES);

View File

@ -71,7 +71,7 @@ pub mod driver;
pub mod pretty;
pub fn run(args: Vec<String>) -> int {
monitor(proc() run_compiler(args.as_slice()));
monitor(move |:| run_compiler(args.as_slice()));
0
}
@ -471,7 +471,7 @@ pub fn list_metadata(sess: &Session, path: &Path,
///
/// The diagnostic emitter yielded to the procedure should be used for reporting
/// errors of the compiler.
pub fn monitor(f: proc():Send) {
pub fn monitor<F:FnOnce()+Send>(f: F) {
static STACK_SIZE: uint = 32000000; // 32MB
let (tx, rx) = channel();

View File

@ -136,7 +136,7 @@ mod callee;
/// closures defined within the function. For example:
///
/// fn foo() {
/// bar(proc() { ... })
/// bar(move|| { ... })
/// }
///
/// Here, the function `foo()` and the closure passed to

View File

@ -342,7 +342,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
let cr = Path::new(cratefile);
info!("starting to run rustc");
let (mut krate, analysis) = std::task::try(proc() {
let (mut krate, analysis) = std::task::try(move |:| {
let cr = cr;
core::run_core(libs, cfgs, externs, &cr, triple)
}).map_err(|_| "rustc failed").unwrap();

View File

@ -15,6 +15,7 @@ use std::io;
use std::os;
use std::str;
use std::string::String;
use std::thunk::Thunk;
use std::collections::{HashSet, HashMap};
use testing;
@ -142,7 +143,7 @@ fn runtest(test: &str, cratename: &str, libs: Vec<Path>, externs: core::Externs,
let w1 = io::ChanWriter::new(tx);
let w2 = w1.clone();
let old = io::stdio::set_stderr(box w1);
spawn(proc() {
spawn(move |:| {
let mut p = io::ChanReader::new(rx);
let mut err = match old {
Some(old) => {
@ -282,7 +283,7 @@ impl Collector {
ignore: should_ignore,
should_fail: testing::ShouldFail::No, // compiler failures are test failures
},
testfn: testing::DynTestFn(proc() {
testfn: testing::DynTestFn(Thunk::new(move|| {
runtest(test.as_slice(),
cratename.as_slice(),
libs,
@ -290,7 +291,7 @@ impl Collector {
should_fail,
no_run,
as_test_harness);
}),
}))
});
}

View File

@ -639,7 +639,7 @@ mod tests {
#[test]
fn test_to_c_str_fail() {
assert!(task::try(proc() { "he\x00llo".to_c_str() }).is_err());
assert!(task::try(move|| { "he\x00llo".to_c_str() }).is_err());
}
#[test]

View File

@ -99,7 +99,7 @@ mod tests {
let (tx, rx) = channel();
futures.push(rx);
task::spawn(proc() {
task::spawn(move || {
for _ in range(0u, count) {
**total.lock() += 1;
}

View File

@ -59,7 +59,7 @@ mod test {
#[test]
fn thread_local_task_smoke_test() {
Thread::start(proc() {
Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
let task: Box<Task> = Local::take();
@ -69,7 +69,7 @@ mod test {
#[test]
fn thread_local_task_two_instances() {
Thread::start(proc() {
Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
let task: Box<Task> = Local::take();
@ -83,7 +83,7 @@ mod test {
#[test]
fn borrow_smoke_test() {
Thread::start(proc() {
Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
@ -97,7 +97,7 @@ mod test {
#[test]
fn borrow_with_return() {
Thread::start(proc() {
Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);
@ -112,7 +112,7 @@ mod test {
#[test]
fn try_take() {
Thread::start(proc() {
Thread::start(move|| {
let task = box Task::new(None, None);
Local::put(task);

View File

@ -680,7 +680,7 @@ mod test {
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
let guard = LK.lock();
let t = Thread::start(proc() {
let t = Thread::start(move|| {
let guard = LK.lock();
guard.signal();
});
@ -705,7 +705,7 @@ mod test {
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
LK.lock_noguard();
let t = Thread::start(proc() {
let t = Thread::start(move|| {
LK.lock_noguard();
LK.signal_noguard();
LK.unlock_noguard();

View File

@ -37,19 +37,20 @@
use kinds::Send;
use mem;
use ops::Drop;
use ops::{Drop, FnOnce};
use option::Option;
use option::Option::{Some, None};
use ptr::RawPtr;
use ptr;
use raw;
use slice::AsSlice;
use thunk::{Thunk};
/// The type representing a foreign chunk of memory
pub struct CVec<T> {
base: *mut T,
len: uint,
dtor: Option<proc():Send>,
dtor: Option<Thunk>,
}
#[unsafe_destructor]
@ -57,7 +58,7 @@ impl<T> Drop for CVec<T> {
fn drop(&mut self) {
match self.dtor.take() {
None => (),
Some(f) => f()
Some(f) => f.invoke(())
}
}
}
@ -90,15 +91,20 @@ impl<T> CVec<T> {
///
/// * base - A foreign pointer to a buffer
/// * len - The number of elements in the buffer
/// * dtor - A proc to run when the value is destructed, useful
/// * dtor - A fn to run when the value is destructed, useful
/// for freeing the buffer, etc.
pub unsafe fn new_with_dtor(base: *mut T, len: uint,
dtor: proc():Send) -> CVec<T> {
pub unsafe fn new_with_dtor<F>(base: *mut T,
len: uint,
dtor: F)
-> CVec<T>
where F : FnOnce(), F : Send
{
assert!(base != ptr::null_mut());
let dtor: Thunk = Thunk::new(dtor);
CVec {
base: base,
len: len,
dtor: Some(dtor),
dtor: Some(dtor)
}
}
@ -177,8 +183,9 @@ mod tests {
let mem = libc::malloc(n as libc::size_t);
if mem.is_null() { ::alloc::oom() }
CVec::new_with_dtor(mem as *mut u8, n,
proc() { libc::free(mem as *mut libc::c_void); })
CVec::new_with_dtor(mem as *mut u8,
n,
move|| { libc::free(mem as *mut libc::c_void); })
}
}
@ -218,8 +225,9 @@ mod tests {
#[test]
fn test_unwrap() {
unsafe {
let cv = CVec::new_with_dtor(1 as *mut int, 0,
proc() { panic!("Don't run this destructor!") });
let cv = CVec::new_with_dtor(1 as *mut int,
0,
move|:| panic!("Don't run this destructor!"));
let p = cv.unwrap();
assert_eq!(p, 1 as *mut int);
}

View File

@ -72,7 +72,7 @@
//! ```
//! // Create a simple streaming channel
//! let (tx, rx) = channel();
//! spawn(proc() {
//! spawn(move|| {
//! tx.send(10i);
//! });
//! assert_eq!(rx.recv(), 10i);
@ -87,7 +87,7 @@
//! let (tx, rx) = channel();
//! for i in range(0i, 10i) {
//! let tx = tx.clone();
//! spawn(proc() {
//! spawn(move|| {
//! tx.send(i);
//! })
//! }
@ -112,7 +112,7 @@
//!
//! ```
//! let (tx, rx) = sync_channel::<int>(0);
//! spawn(proc() {
//! spawn(move|| {
//! // This will wait for the parent task to start receiving
//! tx.send(53);
//! });
@ -465,7 +465,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
/// let (tx, rx) = channel();
///
/// // Spawn off an expensive computation
/// spawn(proc() {
/// spawn(move|| {
/// # fn expensive_computation() {}
/// tx.send(expensive_computation());
/// });
@ -504,7 +504,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
/// // this returns immediately
/// tx.send(1i);
///
/// spawn(proc() {
/// spawn(move|| {
/// // this will block until the previous message has been received
/// tx.send(2i);
/// });
@ -1065,7 +1065,7 @@ mod test {
test!(fn smoke_threads() {
let (tx, rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
tx.send(1);
});
assert_eq!(rx.recv(), 1);
@ -1093,7 +1093,7 @@ mod test {
test!(fn port_gone_concurrent() {
let (tx, rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
rx.recv();
});
loop { tx.send(1) }
@ -1102,7 +1102,7 @@ mod test {
test!(fn port_gone_concurrent_shared() {
let (tx, rx) = channel::<int>();
let tx2 = tx.clone();
spawn(proc() {
spawn(move|| {
rx.recv();
});
loop {
@ -1127,7 +1127,7 @@ mod test {
test!(fn chan_gone_concurrent() {
let (tx, rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
tx.send(1);
tx.send(1);
});
@ -1136,7 +1136,7 @@ mod test {
test!(fn stress() {
let (tx, rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
for _ in range(0u, 10000) { tx.send(1i); }
});
for _ in range(0u, 10000) {
@ -1150,7 +1150,7 @@ mod test {
let (tx, rx) = channel::<int>();
let (dtx, drx) = channel::<()>();
spawn(proc() {
spawn(move|| {
for _ in range(0, AMT * NTHREADS) {
assert_eq!(rx.recv(), 1);
}
@ -1163,7 +1163,7 @@ mod test {
for _ in range(0, NTHREADS) {
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
for _ in range(0, AMT) { tx.send(1); }
});
}
@ -1177,7 +1177,7 @@ mod test {
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
let tx4 = tx3.clone();
spawn(proc() {
spawn(move|| {
tx1.send(());
for _ in range(0i, 40) {
assert_eq!(rx2.recv(), 1);
@ -1185,7 +1185,7 @@ mod test {
tx3.send(());
});
rx1.recv();
spawn(proc() {
spawn(move|| {
for _ in range(0i, 40) {
tx2.send(1);
}
@ -1199,7 +1199,7 @@ mod test {
fn recv_from_outside_runtime() {
let (tx, rx) = channel::<int>();
let (dtx, drx) = channel();
spawn(proc() {
spawn(move|| {
for _ in range(0i, 40) {
assert_eq!(rx.recv(), 1);
}
@ -1217,12 +1217,12 @@ mod test {
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
let tx4 = tx3.clone();
spawn(proc() {
spawn(move|| {
assert_eq!(rx1.recv(), 1);
tx2.send(2);
tx4.send(());
});
spawn(proc() {
spawn(move|| {
tx1.send(1);
assert_eq!(rx2.recv(), 2);
tx3.send(());
@ -1252,7 +1252,7 @@ mod test {
test!(fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
let res = task::try(proc() {
let res = task::try(move|| {
let (tx, rx) = channel::<int>();
drop(tx);
rx.recv();
@ -1312,7 +1312,7 @@ mod test {
test!(fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = channel::<Box<int>>();
spawn(proc() {
spawn(move|| {
assert!(rx.recv() == box 10);
});
@ -1321,10 +1321,10 @@ mod test {
test!(fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = channel::<Box<int>>();
spawn(proc() {
spawn(move|| {
drop(tx);
});
let res = task::try(proc() {
let res = task::try(move|| {
assert!(rx.recv() == box 10);
});
assert!(res.is_err());
@ -1333,7 +1333,7 @@ mod test {
test!(fn oneshot_multi_thread_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
drop(rx);
});
drop(tx);
@ -1343,10 +1343,10 @@ mod test {
test!(fn oneshot_multi_thread_send_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
drop(rx);
});
let _ = task::try(proc() {
let _ = task::try(move|| {
tx.send(1);
});
}
@ -1355,14 +1355,14 @@ mod test {
test!(fn oneshot_multi_thread_recv_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel::<int>();
spawn(proc() {
let res = task::try(proc() {
spawn(move|| {
let res = task::try(move|| {
rx.recv();
});
assert!(res.is_err());
});
spawn(proc() {
spawn(proc() {
spawn(move|| {
spawn(move|| {
drop(tx);
});
});
@ -1372,10 +1372,10 @@ mod test {
test!(fn oneshot_multi_thread_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
tx.send(box 10i);
});
spawn(proc() {
spawn(move|| {
assert!(rx.recv() == box 10i);
});
}
@ -1391,7 +1391,7 @@ mod test {
fn send(tx: Sender<Box<int>>, i: int) {
if i == 10 { return }
spawn(proc() {
spawn(move|| {
tx.send(box i);
send(tx, i + 1);
});
@ -1400,7 +1400,7 @@ mod test {
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
spawn(proc() {
spawn(move|| {
assert!(rx.recv() == box i);
recv(rx, i + 1);
});
@ -1420,7 +1420,7 @@ mod test {
let total = stress_factor() + 100;
for _ in range(0, total) {
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
tx.send(());
});
}
@ -1434,7 +1434,7 @@ mod test {
let (tx, rx) = channel::<int>();
let (total_tx, total_rx) = channel::<int>();
spawn(proc() {
spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
@ -1453,7 +1453,7 @@ mod test {
let (tx, rx) = channel::<int>();
let (count_tx, count_rx) = channel();
spawn(proc() {
spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
@ -1477,7 +1477,7 @@ mod test {
let (tx1, rx1) = channel::<int>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
spawn(proc() {
spawn(move|| {
rx2.recv();
tx1.send(1);
tx3.send(());
@ -1501,7 +1501,7 @@ mod test {
test!(fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
rx.recv(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(());
@ -1522,7 +1522,7 @@ mod test {
use rustrt::thread::Thread;
let (tx, rx) = channel();
let t = Thread::start(proc() {
let t = Thread::start(move|| {
for _ in range(0u, 1000) {
tx.send(());
}
@ -1538,7 +1538,7 @@ mod test {
let (tx, rx) = channel();
let (cdone, pdone) = channel();
let t = Thread::start(proc() {
let t = Thread::start(move|| {
let mut hits = 0u;
while hits < 10 {
match rx.try_recv() {
@ -1591,7 +1591,7 @@ mod sync_tests {
test!(fn smoke_threads() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
tx.send(1);
});
assert_eq!(rx.recv(), 1);
@ -1613,7 +1613,7 @@ mod sync_tests {
test!(fn port_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
rx.recv();
});
loop { tx.send(1) }
@ -1622,7 +1622,7 @@ mod sync_tests {
test!(fn port_gone_concurrent_shared() {
let (tx, rx) = sync_channel::<int>(0);
let tx2 = tx.clone();
spawn(proc() {
spawn(move|| {
rx.recv();
});
loop {
@ -1647,7 +1647,7 @@ mod sync_tests {
test!(fn chan_gone_concurrent() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
tx.send(1);
tx.send(1);
});
@ -1656,7 +1656,7 @@ mod sync_tests {
test!(fn stress() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
for _ in range(0u, 10000) { tx.send(1); }
});
for _ in range(0u, 10000) {
@ -1670,7 +1670,7 @@ mod sync_tests {
let (tx, rx) = sync_channel::<int>(0);
let (dtx, drx) = sync_channel::<()>(0);
spawn(proc() {
spawn(move|| {
for _ in range(0, AMT * NTHREADS) {
assert_eq!(rx.recv(), 1);
}
@ -1683,7 +1683,7 @@ mod sync_tests {
for _ in range(0, NTHREADS) {
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
for _ in range(0, AMT) { tx.send(1); }
});
}
@ -1712,7 +1712,7 @@ mod sync_tests {
test!(fn oneshot_single_thread_recv_chan_close() {
// Receiving on a closed chan will panic
let res = task::try(proc() {
let res = task::try(move|| {
let (tx, rx) = sync_channel::<int>(0);
drop(tx);
rx.recv();
@ -1777,7 +1777,7 @@ mod sync_tests {
test!(fn oneshot_multi_task_recv_then_send() {
let (tx, rx) = sync_channel::<Box<int>>(0);
spawn(proc() {
spawn(move|| {
assert!(rx.recv() == box 10);
});
@ -1786,10 +1786,10 @@ mod sync_tests {
test!(fn oneshot_multi_task_recv_then_close() {
let (tx, rx) = sync_channel::<Box<int>>(0);
spawn(proc() {
spawn(move|| {
drop(tx);
});
let res = task::try(proc() {
let res = task::try(move|| {
assert!(rx.recv() == box 10);
});
assert!(res.is_err());
@ -1798,7 +1798,7 @@ mod sync_tests {
test!(fn oneshot_multi_thread_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
drop(rx);
});
drop(tx);
@ -1808,10 +1808,10 @@ mod sync_tests {
test!(fn oneshot_multi_thread_send_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
drop(rx);
});
let _ = task::try(proc() {
let _ = task::try(move|| {
tx.send(1);
});
}
@ -1820,14 +1820,14 @@ mod sync_tests {
test!(fn oneshot_multi_thread_recv_close_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
let res = task::try(proc() {
spawn(move|| {
let res = task::try(move|| {
rx.recv();
});
assert!(res.is_err());
});
spawn(proc() {
spawn(proc() {
spawn(move|| {
spawn(move|| {
drop(tx);
});
});
@ -1837,10 +1837,10 @@ mod sync_tests {
test!(fn oneshot_multi_thread_send_recv_stress() {
for _ in range(0, stress_factor()) {
let (tx, rx) = sync_channel::<Box<int>>(0);
spawn(proc() {
spawn(move|| {
tx.send(box 10i);
});
spawn(proc() {
spawn(move|| {
assert!(rx.recv() == box 10i);
});
}
@ -1856,7 +1856,7 @@ mod sync_tests {
fn send(tx: SyncSender<Box<int>>, i: int) {
if i == 10 { return }
spawn(proc() {
spawn(move|| {
tx.send(box i);
send(tx, i + 1);
});
@ -1865,7 +1865,7 @@ mod sync_tests {
fn recv(rx: Receiver<Box<int>>, i: int) {
if i == 10 { return }
spawn(proc() {
spawn(move|| {
assert!(rx.recv() == box i);
recv(rx, i + 1);
});
@ -1885,7 +1885,7 @@ mod sync_tests {
let total = stress_factor() + 100;
for _ in range(0, total) {
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
tx.send(());
});
}
@ -1899,7 +1899,7 @@ mod sync_tests {
let (tx, rx) = sync_channel::<int>(0);
let (total_tx, total_rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
let mut acc = 0;
for x in rx.iter() {
acc += x;
@ -1918,7 +1918,7 @@ mod sync_tests {
let (tx, rx) = sync_channel::<int>(0);
let (count_tx, count_rx) = sync_channel(0);
spawn(proc() {
spawn(move|| {
let mut count = 0;
for x in rx.iter() {
if count >= 3 {
@ -1942,7 +1942,7 @@ mod sync_tests {
let (tx1, rx1) = sync_channel::<int>(1);
let (tx2, rx2) = sync_channel::<()>(1);
let (tx3, rx3) = sync_channel::<()>(1);
spawn(proc() {
spawn(move|| {
rx2.recv();
tx1.send(1);
tx3.send(());
@ -1966,7 +1966,7 @@ mod sync_tests {
test!(fn destroy_upgraded_shared_port_when_sender_still_active() {
let (tx, rx) = sync_channel::<()>(0);
let (tx2, rx2) = sync_channel::<()>(0);
spawn(proc() {
spawn(move|| {
rx.recv(); // wait on a oneshot
drop(rx); // destroy a shared
tx2.send(());
@ -1988,7 +1988,7 @@ mod sync_tests {
let (tx, rx) = sync_channel::<()>(0);
let (cdone, pdone) = channel();
let t = Thread::start(proc() {
let t = Thread::start(move|| {
let mut hits = 0u;
while hits < 10 {
match rx.try_recv() {
@ -2008,20 +2008,20 @@ mod sync_tests {
test!(fn send_opt1() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() { rx.recv(); });
spawn(move|| { rx.recv(); });
assert_eq!(tx.send_opt(1), Ok(()));
})
test!(fn send_opt2() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() { drop(rx); });
spawn(move|| { drop(rx); });
assert_eq!(tx.send_opt(1), Err(1));
})
test!(fn send_opt3() {
let (tx, rx) = sync_channel::<int>(1);
assert_eq!(tx.send_opt(1), Ok(()));
spawn(proc() { drop(rx); });
spawn(move|| { drop(rx); });
assert_eq!(tx.send_opt(1), Err(1));
})
@ -2030,11 +2030,11 @@ mod sync_tests {
let tx2 = tx.clone();
let (done, donerx) = channel();
let done2 = done.clone();
spawn(proc() {
spawn(move|| {
assert_eq!(tx.send_opt(1), Err(1));
done.send(());
});
spawn(proc() {
spawn(move|| {
assert_eq!(tx2.send_opt(2), Err(2));
done2.send(());
});
@ -2063,7 +2063,7 @@ mod sync_tests {
test!(fn try_send4() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
for _ in range(0u, 1000) { task::deschedule(); }
assert_eq!(tx.try_send(1), Ok(()));
});
@ -2075,7 +2075,7 @@ mod sync_tests {
let (tx1, rx1) = sync_channel::<()>(3);
let (tx2, rx2) = sync_channel::<()>(3);
spawn(proc() {
spawn(move|| {
rx1.recv();
tx2.try_send(()).unwrap();
});

View File

@ -178,7 +178,7 @@ mod tests {
for _ in range(0, nthreads) {
let tx = tx.clone();
let q = q.clone();
spawn(proc() {
spawn(move|| {
for i in range(0, nmsgs) {
q.push(i);
}

View File

@ -403,7 +403,7 @@ mod test {
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<int>();
spawn(proc() {
spawn(move|| {
for _ in range(0u, 20) { task::deschedule(); }
tx1.send(1);
rx3.recv();
@ -426,7 +426,7 @@ mod test {
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
spawn(proc() {
spawn(move|| {
for _ in range(0u, 20) { task::deschedule(); }
tx1.send(1);
tx2.send(2);
@ -452,7 +452,7 @@ mod test {
let (tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
spawn(proc() {
spawn(move|| {
for i in range(0, AMT) {
if i % 2 == 0 {
tx1.send(i);
@ -477,7 +477,7 @@ mod test {
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
spawn(proc() {
spawn(move|| {
rx3.recv();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty));
@ -498,7 +498,7 @@ mod test {
let (_tx2, rx2) = channel::<int>();
let (tx3, rx3) = channel::<()>();
spawn(proc() {
spawn(move|| {
rx3.recv();
tx1.clone();
assert_eq!(rx3.try_recv(), Err(Empty));
@ -518,7 +518,7 @@ mod test {
let (tx1, rx1) = channel::<()>();
let (tx2, rx2) = channel::<()>();
let (tx3, rx3) = channel::<()>();
spawn(proc() {
spawn(move|| {
let s = Select::new();
let mut h1 = s.handle(&rx1);
let mut h2 = s.handle(&rx2);
@ -624,7 +624,7 @@ mod test {
test!(fn oneshot_data_waiting() {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
select! {
() = rx1.recv() => {}
}
@ -643,7 +643,7 @@ mod test {
tx1.send(());
rx1.recv();
rx1.recv();
spawn(proc() {
spawn(move|| {
select! {
() = rx1.recv() => {}
}
@ -661,7 +661,7 @@ mod test {
drop(tx1.clone());
tx1.send(());
rx1.recv();
spawn(proc() {
spawn(move|| {
select! {
() = rx1.recv() => {}
}
@ -683,7 +683,7 @@ mod test {
test!(fn sync2() {
let (tx, rx) = sync_channel::<int>(0);
spawn(proc() {
spawn(move|| {
for _ in range(0u, 100) { task::deschedule() }
tx.send(1);
});
@ -695,8 +695,8 @@ mod test {
test!(fn sync3() {
let (tx1, rx1) = sync_channel::<int>(0);
let (tx2, rx2): (Sender<int>, Receiver<int>) = channel();
spawn(proc() { tx1.send(1); });
spawn(proc() { tx2.send(2); });
spawn(move|| { tx1.send(1); });
spawn(move|| { tx2.send(2); });
select! {
n = rx1.recv() => {
assert_eq!(n, 1);

View File

@ -316,7 +316,7 @@ mod test {
let (tx, rx) = channel();
let q2 = q.clone();
spawn(proc() {
spawn(move|| {
for _ in range(0u, 100000) {
loop {
match q2.pop() {

View File

@ -161,7 +161,7 @@ mod test {
#[test]
fn test_rx_reader() {
let (tx, rx) = channel();
task::spawn(proc() {
task::spawn(move|| {
tx.send(vec![1u8, 2u8]);
tx.send(vec![]);
tx.send(vec![3u8, 4u8]);
@ -203,7 +203,7 @@ mod test {
#[test]
fn test_rx_buffer() {
let (tx, rx) = channel();
task::spawn(proc() {
task::spawn(move|| {
tx.send(b"he".to_vec());
tx.send(b"llo wo".to_vec());
tx.send(b"".to_vec());
@ -229,7 +229,7 @@ mod test {
writer.write_be_u32(42).unwrap();
let wanted = vec![0u8, 0u8, 0u8, 42u8];
let got = match task::try(proc() { rx.recv() }) {
let got = match task::try(move|| { rx.recv() }) {
Ok(got) => got,
Err(_) => panic!(),
};

View File

@ -119,7 +119,7 @@
//! for stream in acceptor.incoming() {
//! match stream {
//! Err(e) => { /* connection failed */ }
//! Ok(stream) => spawn(proc() {
//! Ok(stream) => spawn(move|| {
//! // connection succeeded
//! handle_client(stream)
//! })

View File

@ -273,13 +273,16 @@ mod tests {
use io::fs::PathExtensions;
use time::Duration;
pub fn smalltest(server: proc(UnixStream):Send, client: proc(UnixStream):Send) {
pub fn smalltest<F,G>(server: F, client: G)
where F : FnOnce(UnixStream), F : Send,
G : FnOnce(UnixStream), G : Send
{
let path1 = next_test_unix();
let path2 = path1.clone();
let mut acceptor = UnixListener::bind(&path1).listen();
spawn(proc() {
spawn(move|| {
match UnixStream::connect(&path2) {
Ok(c) => client(c),
Err(e) => panic!("failed connect: {}", e),
@ -321,11 +324,11 @@ mod tests {
#[test]
fn smoke() {
smalltest(proc(mut server) {
smalltest(move |mut server| {
let mut buf = [0];
server.read(&mut buf).unwrap();
assert!(buf[0] == 99);
}, proc(mut client) {
}, move|mut client| {
client.write(&[99]).unwrap();
})
}
@ -333,18 +336,18 @@ mod tests {
#[cfg_attr(windows, ignore)] // FIXME(#12516)
#[test]
fn read_eof() {
smalltest(proc(mut server) {
smalltest(move|mut server| {
let mut buf = [0];
assert!(server.read(&mut buf).is_err());
assert!(server.read(&mut buf).is_err());
}, proc(_client) {
}, move|_client| {
// drop the client
})
}
#[test]
fn write_begone() {
smalltest(proc(mut server) {
smalltest(move|mut server| {
let buf = [0];
loop {
match server.write(&buf) {
@ -358,7 +361,7 @@ mod tests {
}
}
}
}, proc(_client) {
}, move|_client| {
// drop the client
})
}
@ -374,7 +377,7 @@ mod tests {
Err(e) => panic!("failed listen: {}", e),
};
spawn(proc() {
spawn(move|| {
for _ in range(0u, times) {
let mut stream = UnixStream::connect(&path2);
match stream.write(&[100]) {
@ -408,7 +411,7 @@ mod tests {
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr);
let mut buf = [0, 0];
debug!("client reading");
@ -424,7 +427,7 @@ mod tests {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
rx1.recv();
debug!("writer writing");
@ -447,7 +450,7 @@ mod tests {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr);
s.write(&[1]).unwrap();
rx.recv();
@ -459,7 +462,7 @@ mod tests {
let s2 = s1.clone();
let (done, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
@ -478,7 +481,7 @@ mod tests {
let addr = next_test_unix();
let mut acceptor = UnixListener::bind(&addr).listen();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr);
let buf = &mut [0, 1];
s.read(buf).unwrap();
@ -489,7 +492,7 @@ mod tests {
let s2 = s1.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
tx.send(());
@ -536,7 +539,7 @@ mod tests {
// continue to receive any pending connections.
let (tx, rx) = channel();
let addr2 = addr.clone();
spawn(proc() {
spawn(move|| {
tx.send(UnixStream::connect(&addr2).unwrap());
});
let l = rx.recv();
@ -554,7 +557,7 @@ mod tests {
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
let addr2 = addr.clone();
spawn(proc() {
spawn(move|| {
drop(UnixStream::connect(&addr2).unwrap());
});
a.accept().unwrap();
@ -592,7 +595,7 @@ mod tests {
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
@ -629,7 +632,7 @@ mod tests {
let addr = next_test_unix();
let a = UnixListener::bind(&addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
@ -638,7 +641,7 @@ mod tests {
let mut s = UnixStream::connect(&addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(());
@ -655,7 +658,7 @@ mod tests {
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
@ -693,7 +696,7 @@ mod tests {
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
let mut amt = 0;
@ -722,7 +725,7 @@ mod tests {
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
@ -749,7 +752,7 @@ mod tests {
let addr = next_test_unix();
let mut a = UnixListener::bind(&addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = UnixStream::connect(&addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
@ -759,7 +762,7 @@ mod tests {
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_ok());
tx2.send(());
@ -781,10 +784,10 @@ mod tests {
let mut a2 = a.clone();
let addr2 = addr.clone();
spawn(proc() {
spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
spawn(proc() {
spawn(move|| {
let _ = UnixStream::connect(&addr);
});
@ -804,14 +807,14 @@ mod tests {
let (tx, rx) = channel();
let tx2 = tx.clone();
spawn(proc() { let mut a = a; tx.send(a.accept()) });
spawn(proc() { let mut a = a2; tx2.send(a.accept()) });
spawn(move|| { let mut a = a; tx.send(a.accept()) });
spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
let addr2 = addr.clone();
spawn(proc() {
spawn(move|| {
let _ = UnixStream::connect(&addr2);
});
spawn(proc() {
spawn(move|| {
let _ = UnixStream::connect(&addr);
});
@ -837,7 +840,7 @@ mod tests {
let mut a2 = a.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut a = a;
tx.send(a.accept());
});

View File

@ -140,7 +140,7 @@ impl TcpStream {
/// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
/// let stream2 = stream.clone();
///
/// spawn(proc() {
/// spawn(move|| {
/// // close this stream after one second
/// timer::sleep(Duration::seconds(1));
/// let mut stream = stream2;
@ -293,7 +293,7 @@ impl sys_common::AsInner<TcpStreamImp> for TcpStream {
/// for stream in acceptor.incoming() {
/// match stream {
/// Err(e) => { /* connection failed */ }
/// Ok(stream) => spawn(proc() {
/// Ok(stream) => spawn(move|| {
/// // connection succeeded
/// handle_client(stream)
/// })
@ -420,7 +420,7 @@ impl TcpAcceptor {
/// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap();
/// let a2 = a.clone();
///
/// spawn(proc() {
/// spawn(move|| {
/// let mut a2 = a2;
/// for socket in a2.incoming() {
/// match socket {
@ -509,7 +509,7 @@ mod test {
let listener = TcpListener::bind(socket_addr);
let mut acceptor = listener.listen();
spawn(proc() {
spawn(move|| {
let mut stream = TcpStream::connect(("localhost", socket_addr.port));
stream.write(&[144]).unwrap();
});
@ -525,7 +525,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut stream = TcpStream::connect(("localhost", addr.port));
stream.write(&[64]).unwrap();
});
@ -541,7 +541,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut stream = TcpStream::connect(("127.0.0.1", addr.port));
stream.write(&[44]).unwrap();
});
@ -557,7 +557,7 @@ mod test {
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut stream = TcpStream::connect(("::1", addr.port));
stream.write(&[66]).unwrap();
});
@ -573,7 +573,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
@ -589,7 +589,7 @@ mod test {
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
});
@ -605,7 +605,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
@ -621,7 +621,7 @@ mod test {
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
@ -637,7 +637,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
@ -661,7 +661,7 @@ mod test {
let addr = next_test_ip6();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let _stream = TcpStream::connect(addr);
// Close
});
@ -686,7 +686,7 @@ mod test {
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(());
});
@ -711,7 +711,7 @@ mod test {
let mut acceptor = TcpListener::bind(addr).listen();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
drop(TcpStream::connect(addr));
tx.send(());
});
@ -736,7 +736,7 @@ mod test {
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
for _ in range(0, max) {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
@ -756,7 +756,7 @@ mod test {
let max = 10u;
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
for _ in range(0, max) {
let mut stream = TcpStream::connect(addr);
stream.write(&[99]).unwrap();
@ -776,11 +776,11 @@ mod test {
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
spawn(proc() {
spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
@ -795,7 +795,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
spawn(proc() {
spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
@ -812,11 +812,11 @@ mod test {
static MAX: int = 10;
let acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut acceptor = acceptor;
for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) {
// Start another task to handle the connection
spawn(proc() {
spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
@ -831,7 +831,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
spawn(proc() {
spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
@ -848,11 +848,11 @@ mod test {
let addr = next_test_ip4();
let acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
spawn(proc() {
spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
@ -867,7 +867,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
spawn(proc() {
spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
@ -884,11 +884,11 @@ mod test {
let addr = next_test_ip6();
let acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut acceptor = acceptor;
for stream in acceptor.incoming().take(MAX as uint) {
// Start another task to handle the connection
spawn(proc() {
spawn(move|| {
let mut stream = stream;
let mut buf = [0];
stream.read(&mut buf).unwrap();
@ -903,7 +903,7 @@ mod test {
fn connect(i: int, addr: SocketAddr) {
if i == MAX { return }
spawn(proc() {
spawn(move|| {
debug!("connecting");
let mut stream = TcpStream::connect(addr);
// Connect again before writing
@ -926,7 +926,7 @@ mod test {
pub fn peer_name(addr: SocketAddr) {
let acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut acceptor = acceptor;
acceptor.accept().unwrap();
});
@ -961,7 +961,7 @@ mod test {
fn partial_read() {
let addr = next_test_ip4();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut srv = TcpListener::bind(addr).listen().unwrap();
tx.send(());
let mut cl = srv.accept().unwrap();
@ -998,7 +998,7 @@ mod test {
let addr = next_test_ip4();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
rx.recv();
let _stream = TcpStream::connect(addr).unwrap();
// Close
@ -1023,7 +1023,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 0];
assert_eq!(s.read(&mut buf), Ok(1));
@ -1036,7 +1036,7 @@ mod test {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
rx1.recv();
s2.write(&[1]).unwrap();
@ -1055,7 +1055,7 @@ mod test {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr);
s.write(&[1]).unwrap();
rx.recv();
@ -1067,7 +1067,7 @@ mod test {
let s2 = s1.clone();
let (done, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
let mut buf = [0, 0];
s2.read(&mut buf).unwrap();
@ -1086,7 +1086,7 @@ mod test {
let addr = next_test_ip4();
let mut acceptor = TcpListener::bind(addr).listen();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr);
let mut buf = [0, 1];
s.read(&mut buf).unwrap();
@ -1097,7 +1097,7 @@ mod test {
let s2 = s1.clone();
let (done, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
s2.write(&[1]).unwrap();
done.send(());
@ -1111,7 +1111,7 @@ mod test {
fn shutdown_smoke() {
let addr = next_test_ip4();
let a = TcpListener::bind(addr).unwrap().listen();
spawn(proc() {
spawn(move|| {
let mut a = a;
let mut c = a.accept().unwrap();
assert_eq!(c.read_to_end(), Ok(vec!()));
@ -1145,7 +1145,7 @@ mod test {
// flakiness.
if !cfg!(target_os = "freebsd") {
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
tx.send(TcpStream::connect(addr).unwrap());
});
let _l = rx.recv();
@ -1162,7 +1162,7 @@ mod test {
// Unset the timeout and make sure that this always blocks.
a.set_timeout(None);
spawn(proc() {
spawn(move|| {
drop(TcpStream::connect(addr).unwrap());
});
a.accept().unwrap();
@ -1173,7 +1173,7 @@ mod test {
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
@ -1210,7 +1210,7 @@ mod test {
let addr = next_test_ip4();
let a = TcpListener::bind(addr).listen().unwrap();
let (_tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut a = a;
let _s = a.accept().unwrap();
let _ = rx.recv_opt();
@ -1219,7 +1219,7 @@ mod test {
let mut s = TcpStream::connect(addr).unwrap();
let s2 = s.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
assert!(s2.read(&mut [0]).is_err());
tx.send(());
@ -1236,7 +1236,7 @@ mod test {
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
@ -1269,7 +1269,7 @@ mod test {
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
let mut amt = 0;
@ -1298,7 +1298,7 @@ mod test {
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert!(s.write(&[0]).is_ok());
@ -1326,7 +1326,7 @@ mod test {
let addr = next_test_ip6();
let mut a = TcpListener::bind(addr).listen().unwrap();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let mut s = TcpStream::connect(addr).unwrap();
rx.recv();
assert_eq!(s.write(&[0]), Ok(()));
@ -1336,7 +1336,7 @@ mod test {
let mut s = a.accept().unwrap();
let s2 = s.clone();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let mut s2 = s2;
assert_eq!(s2.read(&mut [0]), Ok(1));
tx2.send(());
@ -1359,7 +1359,7 @@ mod test {
let (tx, rx) = channel();
let (txdone, rxdone) = channel();
let txdone2 = txdone.clone();
spawn(proc() {
spawn(move|| {
let mut tcp = TcpStream::connect(addr).unwrap();
rx.recv();
tcp.write_u8(0).unwrap();
@ -1370,7 +1370,7 @@ mod test {
let tcp = accept.accept().unwrap();
let tcp2 = tcp.clone();
let txdone3 = txdone.clone();
spawn(proc() {
spawn(move|| {
let mut tcp2 = tcp2;
tcp2.read_u8().unwrap();
txdone3.send(());
@ -1396,10 +1396,10 @@ mod test {
let mut a = l.listen().unwrap();
let mut a2 = a.clone();
spawn(proc() {
spawn(move|| {
let _ = TcpStream::connect(addr);
});
spawn(proc() {
spawn(move|| {
let _ = TcpStream::connect(addr);
});
@ -1417,13 +1417,13 @@ mod test {
let (tx, rx) = channel();
let tx2 = tx.clone();
spawn(proc() { let mut a = a; tx.send(a.accept()) });
spawn(proc() { let mut a = a2; tx2.send(a.accept()) });
spawn(move|| { let mut a = a; tx.send(a.accept()) });
spawn(move|| { let mut a = a2; tx2.send(a.accept()) });
spawn(proc() {
spawn(move|| {
let _ = TcpStream::connect(addr);
});
spawn(proc() {
spawn(move|| {
let _ = TcpStream::connect(addr);
});
@ -1449,7 +1449,7 @@ mod test {
let mut a2 = a.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut a = a;
tx.send(a.accept());
});

View File

@ -272,7 +272,7 @@ mod test {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx1.recv();
@ -307,7 +307,7 @@ mod test {
let client_ip = next_test_ip6();
let (tx, rx) = channel::<()>();
spawn(proc() {
spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(ref mut client) => {
rx.recv();
@ -343,7 +343,7 @@ mod test {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let send_as = |ip, val: &[u8]| {
match UdpSocket::bind(ip) {
Ok(client) => {
@ -387,7 +387,7 @@ mod test {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
match UdpSocket::bind(client_ip) {
Ok(client) => {
let client = box client;
@ -449,7 +449,7 @@ mod test {
let mut sock1 = UdpSocket::bind(addr1).unwrap();
let sock2 = UdpSocket::bind(addr2).unwrap();
spawn(proc() {
spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 0];
assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1)));
@ -461,7 +461,7 @@ mod test {
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let mut sock3 = sock3;
rx1.recv();
sock3.send_to(&[1], addr2).unwrap();
@ -482,7 +482,7 @@ mod test {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
spawn(proc() {
spawn(move|| {
let mut sock2 = sock2;
sock2.send_to(&[1], addr1).unwrap();
rx.recv();
@ -493,7 +493,7 @@ mod test {
let sock3 = sock1.clone();
let (done, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut sock3 = sock3;
let mut buf = [0, 0];
sock3.recv_from(&mut buf).unwrap();
@ -517,7 +517,7 @@ mod test {
let (tx, rx) = channel();
let (serv_tx, serv_rx) = channel();
spawn(proc() {
spawn(move|| {
let mut sock2 = sock2;
let mut buf = [0, 1];
@ -533,7 +533,7 @@ mod test {
let (done, rx) = channel();
let tx2 = tx.clone();
spawn(proc() {
spawn(move|| {
let mut sock3 = sock3;
match sock3.send_to(&[1], addr2) {
Ok(..) => { let _ = tx2.send_opt(()); }
@ -560,7 +560,7 @@ mod test {
let (tx, rx) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let mut a = UdpSocket::bind(addr2).unwrap();
assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1)));
assert_eq!(a.send_to(&[0], addr1), Ok(()));

View File

@ -123,7 +123,7 @@ mod test {
let out = PipeStream::open(writer);
let mut input = PipeStream::open(reader);
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let mut out = out;
out.write(&[10]).unwrap();
rx.recv(); // don't close the pipe until the other read has finished

View File

@ -693,7 +693,7 @@ impl Process {
fn read(stream: Option<io::PipeStream>) -> Receiver<IoResult<Vec<u8>>> {
let (tx, rx) = channel();
match stream {
Some(stream) => spawn(proc() {
Some(stream) => spawn(move |:| {
let mut stream = stream;
tx.send(stream.read_to_end())
}),
@ -1155,14 +1155,14 @@ mod tests {
fn wait_timeout2() {
let (tx, rx) = channel();
let tx2 = tx.clone();
spawn(proc() {
spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);
p.signal_kill().unwrap();
tx.send(());
});
spawn(proc() {
spawn(move|| {
let mut p = sleeper();
p.set_timeout(Some(10));
assert_eq!(p.wait().err().unwrap().kind, TimedOut);

View File

@ -528,7 +528,7 @@ mod tests {
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
spawn(proc() {
spawn(move|| {
set_stdout(box w);
println!("hello!");
});
@ -542,7 +542,7 @@ mod tests {
let (tx, rx) = channel();
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
spawn(proc() {
spawn(move|| {
::realstd::io::stdio::set_stderr(box w);
panic!("my special message");
});

View File

@ -357,7 +357,7 @@ mod test {
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
spawn(proc() {
spawn(move|| {
let _ = timer_rx.recv_opt();
});
@ -371,7 +371,7 @@ mod test {
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
spawn(proc() {
spawn(move|| {
let _ = timer_rx.recv_opt();
});
@ -384,7 +384,7 @@ mod test {
let mut timer = Timer::new().unwrap();
let timer_rx = timer.periodic(Duration::milliseconds(1000));
spawn(proc() {
spawn(move|| {
let _ = timer_rx.recv_opt();
});

View File

@ -358,8 +358,8 @@ macro_rules! vec[
/// # fn long_running_task() {}
/// # fn calculate_the_answer() -> int { 42i }
///
/// spawn(proc() { long_running_task(); tx1.send(()) });
/// spawn(proc() { tx2.send(calculate_the_answer()) });
/// spawn(move|| { long_running_task(); tx1.send(()) });
/// spawn(move|| { tx2.send(calculate_the_answer()) });
///
/// select! (
/// () = rx1.recv() => println!("the long running task finished first"),

View File

@ -515,17 +515,17 @@ mod tests {
#[test]
fn test_null_byte() {
use task;
let result = task::try(proc() {
let result = task::try(move|| {
Path::new(b"foo/bar\0")
});
assert!(result.is_err());
let result = task::try(proc() {
let result = task::try(move|| {
Path::new("test").set_filename(b"f\0o")
});
assert!(result.is_err());
let result = task::try(proc() {
let result = task::try(move|| {
Path::new("test").push(b"f\0o");
});
assert!(result.is_err());

View File

@ -1299,17 +1299,17 @@ mod tests {
#[test]
fn test_null_byte() {
use task;
let result = task::try(proc() {
let result = task::try(move|| {
Path::new(b"foo/bar\0")
});
assert!(result.is_err());
let result = task::try(proc() {
let result = task::try(move|| {
Path::new("test").set_filename(b"f\0o")
});
assert!(result.is_err());
let result = task::try(proc() {
let result = task::try(move|| {
Path::new("test").push(b"f\0o");
});
assert!(result.is_err());

View File

@ -355,7 +355,7 @@ mod test {
for _ in range(0u, 20) {
let (tx, rx) = channel();
txs.push(tx);
task::spawn(proc() {
task::spawn(move|| {
// wait until all the tasks are ready to go.
rx.recv();

View File

@ -47,7 +47,7 @@
//! let spinlock = Arc::new(AtomicUint::new(1));
//!
//! let spinlock_clone = spinlock.clone();
//! spawn(proc() {
//! spawn(move|| {
//! spinlock_clone.store(0, SeqCst);
//! });
//!
@ -68,7 +68,7 @@
//! let shared_big_object = Arc::new(AtomicOption::empty());
//!
//! let shared_big_object_clone = shared_big_object.clone();
//! spawn(proc() {
//! spawn(move|| {
//! let unwrapped_big_object = shared_big_object_clone.take(SeqCst);
//! if unwrapped_big_object.is_some() {
//! println!("got a big object from another task");

View File

@ -21,7 +21,7 @@ use sync::{Mutex, Condvar};
/// let c = barrier.clone();
/// // The same messages will be printed together.
/// // You will NOT see any interleaving.
/// spawn(proc() {
/// spawn(move|| {
/// println!("before wait");
/// c.wait();
/// println!("after wait");
@ -94,7 +94,7 @@ mod tests {
for _ in range(0u, 9) {
let c = barrier.clone();
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
c.wait();
tx.send(true);
});

View File

@ -41,7 +41,7 @@ use time::Duration;
/// let pair2 = pair.clone();
///
/// // Inside of our lock, spawn a new thread, and then wait for it to start
/// spawn(proc() {
/// spawn(move|| {
/// let &(ref lock, ref cvar) = &*pair2;
/// let mut started = lock.lock();
/// *started = true;
@ -282,7 +282,7 @@ mod tests {
static M: StaticMutex = MUTEX_INIT;
let g = M.lock();
spawn(proc() {
spawn(move|| {
let _g = M.lock();
C.notify_one();
});
@ -300,7 +300,7 @@ mod tests {
for _ in range(0, N) {
let data = data.clone();
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
let &(ref lock, ref cond) = &*data;
let mut cnt = lock.lock();
*cnt += 1;
@ -334,7 +334,7 @@ mod tests {
let g = M.lock();
assert!(!C.wait_timeout(&g, Duration::nanoseconds(1000)));
spawn(proc() {
spawn(move|| {
let _g = M.lock();
C.notify_one();
});
@ -351,7 +351,7 @@ mod tests {
static C: StaticCondvar = CONDVAR_INIT;
let g = M1.lock();
spawn(proc() {
spawn(move|| {
let _g = M1.lock();
C.notify_one();
});

View File

@ -47,7 +47,7 @@ use sys_common::mutex as sys;
/// let (tx, rx) = channel();
/// for _ in range(0u, 10) {
/// let (data, tx) = (data.clone(), tx.clone());
/// spawn(proc() {
/// spawn(move|| {
/// // The shared static can only be accessed once the lock is held.
/// // Our non-atomic increment is safe because we're the only thread
/// // which can access the shared state when the lock is held.
@ -313,9 +313,9 @@ mod test {
let (tx, rx) = channel();
for _ in range(0, K) {
let tx2 = tx.clone();
spawn(proc() { inc(); tx2.send(()); });
spawn(move|| { inc(); tx2.send(()); });
let tx2 = tx.clone();
spawn(proc() { inc(); tx2.send(()); });
spawn(move|| { inc(); tx2.send(()); });
}
drop(tx);
@ -339,7 +339,7 @@ mod test {
let arc = Arc::new((Mutex::new(false), Condvar::new()));
let arc2 = arc.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
// wait until parent gets in
rx.recv();
let &(ref lock, ref cvar) = &*arc2;
@ -364,7 +364,7 @@ mod test {
let arc2 = arc.clone();
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
rx.recv();
let &(ref lock, ref cvar) = &*arc2;
let _g = lock.lock();
@ -386,7 +386,7 @@ mod test {
fn test_mutex_arc_poison() {
let arc = Arc::new(Mutex::new(1i));
let arc2 = arc.clone();
let _ = task::try(proc() {
let _ = task::try(move|| {
let lock = arc2.lock();
assert_eq!(*lock, 2);
});
@ -401,7 +401,7 @@ mod test {
let arc = Arc::new(Mutex::new(1i));
let arc2 = Arc::new(Mutex::new(arc));
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
let lock = arc2.lock();
let lock2 = lock.deref().lock();
assert_eq!(*lock2, 1);
@ -414,7 +414,7 @@ mod test {
fn test_mutex_arc_access_in_unwind() {
let arc = Arc::new(Mutex::new(1i));
let arc2 = arc.clone();
let _ = task::try::<()>(proc() {
let _ = task::try(move|| -> () {
struct Unwinder {
i: Arc<Mutex<int>>,
}

View File

@ -142,7 +142,7 @@ mod test {
let (tx, rx) = channel();
for _ in range(0u, 10) {
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
for _ in range(0u, 4) { task::deschedule() }
unsafe {
O.doit(|| {

View File

@ -387,7 +387,7 @@ mod tests {
let (tx, rx) = channel::<()>();
for _ in range(0, N) {
let tx = tx.clone();
spawn(proc() {
spawn(move|| {
let mut rng = rand::task_rng();
for _ in range(0, M) {
if rng.gen_weighted_bool(N) {
@ -409,7 +409,7 @@ mod tests {
fn test_rw_arc_poison_wr() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
let _ = task::try(proc() {
let _ = task::try(move|| {
let lock = arc2.write();
assert_eq!(*lock, 2);
});
@ -422,7 +422,7 @@ mod tests {
fn test_rw_arc_poison_ww() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
let _ = task::try(proc() {
let _ = task::try(move|| {
let lock = arc2.write();
assert_eq!(*lock, 2);
});
@ -434,7 +434,7 @@ mod tests {
fn test_rw_arc_no_poison_rr() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
let _ = task::try(proc() {
let _ = task::try(move|| {
let lock = arc2.read();
assert_eq!(*lock, 2);
});
@ -445,7 +445,7 @@ mod tests {
fn test_rw_arc_no_poison_rw() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
let _ = task::try(proc() {
let _ = task::try(move|| {
let lock = arc2.read();
assert_eq!(*lock, 2);
});
@ -459,7 +459,7 @@ mod tests {
let arc2 = arc.clone();
let (tx, rx) = channel();
task::spawn(proc() {
task::spawn(move|| {
let mut lock = arc2.write();
for _ in range(0u, 10) {
let tmp = *lock;
@ -474,7 +474,7 @@ mod tests {
let mut children = Vec::new();
for _ in range(0u, 5) {
let arc3 = arc.clone();
children.push(task::try_future(proc() {
children.push(task::try_future(move|| {
let lock = arc3.read();
assert!(*lock >= 0);
}));
@ -495,7 +495,7 @@ mod tests {
fn test_rw_arc_access_in_unwind() {
let arc = Arc::new(RWLock::new(1i));
let arc2 = arc.clone();
let _ = task::try::<()>(proc() {
let _ = task::try(move|| -> () {
struct Unwinder {
i: Arc<RWLock<int>>,
}

View File

@ -127,7 +127,7 @@ mod tests {
fn test_sem_as_mutex() {
let s = Arc::new(Semaphore::new(1));
let s2 = s.clone();
spawn(proc() {
spawn(move|| {
let _g = s2.access();
});
let _g = s.access();
@ -139,7 +139,7 @@ mod tests {
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
spawn(proc() {
spawn(move|| {
s2.acquire();
tx.send(());
});
@ -150,7 +150,7 @@ mod tests {
let (tx, rx) = channel();
let s = Arc::new(Semaphore::new(0));
let s2 = s.clone();
spawn(proc() {
spawn(move|| {
s2.release();
let _ = rx.recv();
});
@ -166,7 +166,7 @@ mod tests {
let s2 = s.clone();
let (tx1, rx1) = channel();
let (tx2, rx2) = channel();
spawn(proc() {
spawn(move|| {
let _g = s2.access();
let _ = rx2.recv();
tx1.send(());
@ -183,7 +183,7 @@ mod tests {
let (tx, rx) = channel();
{
let _g = s.access();
spawn(proc() {
spawn(move|| {
tx.send(());
drop(s2.access());
tx.send(());

View File

@ -12,17 +12,18 @@
use core::prelude::*;
use task::spawn;
use task::{spawn};
use comm::{channel, Sender, Receiver};
use sync::{Arc, Mutex};
use thunk::Thunk;
struct Sentinel<'a> {
jobs: &'a Arc<Mutex<Receiver<proc(): Send>>>,
jobs: &'a Arc<Mutex<Receiver<Thunk>>>,
active: bool
}
impl<'a> Sentinel<'a> {
fn new(jobs: &Arc<Mutex<Receiver<proc(): Send>>>) -> Sentinel {
fn new(jobs: &Arc<Mutex<Receiver<Thunk>>>) -> Sentinel {
Sentinel {
jobs: jobs,
active: true
@ -60,7 +61,7 @@ impl<'a> Drop for Sentinel<'a> {
/// let (tx, rx) = channel();
/// for _ in range(0, 8u) {
/// let tx = tx.clone();
/// pool.execute(proc() {
/// pool.execute(move|| {
/// tx.send(1u);
/// });
/// }
@ -146,7 +147,7 @@ mod test {
let (tx, rx) = channel();
for _ in range(0, TEST_TASKS) {
let tx = tx.clone();
pool.execute(proc() {
pool.execute(move|| {
tx.send(1u);
});
}
@ -168,14 +169,14 @@ mod test {
// Panic all the existing tasks.
for _ in range(0, TEST_TASKS) {
pool.execute(proc() { panic!() });
pool.execute(move|| -> () { panic!() });
}
// Ensure new tasks were spawned to compensate.
let (tx, rx) = channel();
for _ in range(0, TEST_TASKS) {
let tx = tx.clone();
pool.execute(proc() {
pool.execute(move|| {
tx.send(1u);
});
}
@ -193,7 +194,7 @@ mod test {
// Panic all the existing tasks in a bit.
for _ in range(0, TEST_TASKS) {
let waiter = waiter.clone();
pool.execute(proc() {
pool.execute(move|| {
waiter.wait();
panic!();
});

View File

@ -83,7 +83,7 @@ impl<M: Send> Helper<M> {
*self.signal.get() = send as uint;
let t = f();
task::spawn(proc() {
task::spawn(move |:| {
bookkeeping::decrement();
helper(receive, rx, t);
let _g = self.lock.lock();
@ -91,7 +91,7 @@ impl<M: Send> Helper<M> {
self.cond.notify_one()
});
rustrt::at_exit(proc() { self.shutdown() });
rustrt::at_exit(move|:| { self.shutdown() });
*self.initialized.get() = true;
}
}

View File

@ -94,8 +94,8 @@ impl Process {
mem::transmute::<&ProcessConfig<K,V>,&'static ProcessConfig<K,V>>(cfg)
};
with_envp(cfg.env(), proc(envp) {
with_argv(cfg.program(), cfg.args(), proc(argv) unsafe {
with_envp(cfg.env(), move|: envp: *const c_void| {
with_argv(cfg.program(), cfg.args(), move|: argv: *const *const libc::c_char| unsafe {
let (input, mut output) = try!(sys::os::pipe());
// We may use this in the child, so perform allocations before the

View File

@ -131,7 +131,7 @@ fn init_dtors() {
DTORS = mem::transmute(dtors);
}
rustrt::at_exit(proc() unsafe {
rustrt::at_exit(move|| unsafe {
mem::transmute::<_, Box<Exclusive<Vec<(Key, Dtor)>>>>(DTORS);
DTORS = 0 as *mut _;
});

View File

@ -77,7 +77,7 @@ pub mod scoped;
/// });
///
/// // each thread starts out with the initial value of 1
/// spawn(proc() {
/// spawn(move|| {
/// FOO.with(|f| {
/// assert_eq!(*f.borrow(), 1);
/// *f.borrow_mut() = 3;
@ -471,7 +471,7 @@ mod tests {
*f.get() = 2;
});
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
FOO.with(|f| unsafe {
assert_eq!(*f.get(), 1);
});
@ -491,7 +491,7 @@ mod tests {
})
let (tx, rx) = channel();
spawn(proc() unsafe {
spawn(move|| unsafe {
let mut tx = Some(tx);
FOO.with(|f| {
*f.get() = Some(Foo(tx.take().unwrap()));
@ -539,7 +539,7 @@ mod tests {
}
}
Thread::start(proc() {
Thread::start(move|| {
drop(S1);
}).join();
}
@ -557,7 +557,7 @@ mod tests {
}
}
Thread::start(proc() unsafe {
Thread::start(move|| unsafe {
K1.with(|s| *s.get() = Some(S1));
}).join();
}
@ -584,7 +584,7 @@ mod tests {
}
let (tx, rx) = channel();
spawn(proc() unsafe {
spawn(move|| unsafe {
let mut tx = Some(tx);
K1.with(|s| *s.get() = Some(S1(tx.take().unwrap())));
});

View File

@ -32,7 +32,7 @@
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(asm, macro_rules, phase, globs, slicing_syntax)]
#![feature(unboxed_closures)]
#![feature(unboxed_closures, default_type_params)]
extern crate getopts;
extern crate regex;
@ -71,6 +71,7 @@ use std::str::FromStr;
use std::string::String;
use std::task::TaskBuilder;
use std::time::Duration;
use std::thunk::{Thunk, Invoke};
// to be used by rustc to compile tests in libtest
pub mod test {
@ -149,9 +150,9 @@ pub trait TDynBenchFn {
pub enum TestFn {
StaticTestFn(fn()),
StaticBenchFn(fn(&mut Bencher)),
StaticMetricFn(proc(&mut MetricMap):'static),
DynTestFn(proc():Send),
DynMetricFn(proc(&mut MetricMap):'static),
StaticMetricFn(fn(&mut MetricMap)),
DynTestFn(Thunk),
DynMetricFn(Box<for<'a> Invoke<&'a mut MetricMap>+'static>),
DynBenchFn(Box<TDynBenchFn+'static>)
}
@ -1119,8 +1120,8 @@ pub fn run_test(opts: &TestOpts,
fn run_test_inner(desc: TestDesc,
monitor_ch: Sender<MonitorMsg>,
nocapture: bool,
testfn: proc():Send) {
spawn(proc() {
testfn: Thunk) {
spawn(move || {
let (tx, rx) = channel();
let mut reader = ChanReader::new(rx);
let stdout = ChanWriter::new(tx.clone());
@ -1135,7 +1136,7 @@ pub fn run_test(opts: &TestOpts,
task = task.stdout(box stdout as Box<Writer + Send>);
task = task.stderr(box stderr as Box<Writer + Send>);
}
let result_future = task.try_future(testfn);
let result_future = task.try_future(move || testfn.invoke(()));
let stdout = reader.read_to_end().unwrap().into_iter().collect();
let task_result = result_future.into_inner();
@ -1157,7 +1158,7 @@ pub fn run_test(opts: &TestOpts,
}
DynMetricFn(f) => {
let mut mm = MetricMap::new();
f(&mut mm);
f.invoke(&mut mm);
monitor_ch.send((desc, TrMetrics(mm), Vec::new()));
return;
}
@ -1169,7 +1170,7 @@ pub fn run_test(opts: &TestOpts,
}
DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f),
StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture,
proc() f())
Thunk::new(move|| f()))
}
}
@ -1467,6 +1468,7 @@ mod tests {
Improvement, Regression, LikelyNoise,
StaticTestName, DynTestName, DynTestFn, ShouldFail};
use std::io::TempDir;
use std::thunk::Thunk;
#[test]
pub fn do_not_run_ignored_tests() {
@ -1477,7 +1479,7 @@ mod tests {
ignore: true,
should_fail: ShouldFail::No,
},
testfn: DynTestFn(proc() f()),
testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
@ -1494,7 +1496,7 @@ mod tests {
ignore: true,
should_fail: ShouldFail::No,
},
testfn: DynTestFn(proc() f()),
testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
@ -1511,7 +1513,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::Yes(None)
},
testfn: DynTestFn(proc() f()),
testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
@ -1528,7 +1530,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::Yes(Some("error message"))
},
testfn: DynTestFn(proc() f()),
testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
@ -1545,7 +1547,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::Yes(Some("foobar"))
},
testfn: DynTestFn(proc() f()),
testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
@ -1562,7 +1564,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::Yes(None)
},
testfn: DynTestFn(proc() f()),
testfn: DynTestFn(Thunk::new(move|| f())),
};
let (tx, rx) = channel();
run_test(&TestOpts::new(), false, desc, tx);
@ -1608,7 +1610,7 @@ mod tests {
ignore: true,
should_fail: ShouldFail::No,
},
testfn: DynTestFn(proc() {}),
testfn: DynTestFn(Thunk::new(move|| {})),
},
TestDescAndFn {
desc: TestDesc {
@ -1616,7 +1618,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::No,
},
testfn: DynTestFn(proc() {}),
testfn: DynTestFn(Thunk::new(move|| {})),
});
let filtered = filter_tests(&opts, tests);
@ -1652,7 +1654,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::No,
},
testfn: DynTestFn(testfn),
testfn: DynTestFn(Thunk::new(testfn)),
};
tests.push(test);
}
@ -1693,7 +1695,7 @@ mod tests {
ignore: false,
should_fail: ShouldFail::No,
},
testfn: DynTestFn(test_fn)
testfn: DynTestFn(Thunk::new(test_fn))
}
}).collect();
let filtered = filter_tests(&opts, tests);

View File

@ -12,7 +12,7 @@ use std::task;
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
let (tx, rx) = channel();
task::spawn(proc() {
task::spawn(move|| {
tx.send(x.clone());
});
rx

View File

@ -64,7 +64,7 @@ fn run(args: &[String]) {
let mut worker_results = Vec::new();
for _ in range(0u, workers) {
let to_child = to_child.clone();
worker_results.push(task::try_future(proc() {
worker_results.push(task::try_future(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
@ -72,7 +72,7 @@ fn run(args: &[String]) {
//println!("worker {} exiting", i);
}));
}
task::spawn(proc() {
task::spawn(move|| {
server(&from_parent, &to_parent);
});

View File

@ -58,7 +58,7 @@ fn run(args: &[String]) {
let mut worker_results = Vec::new();
let from_parent = if workers == 1 {
let (to_child, from_parent) = channel();
worker_results.push(task::try_future(proc() {
worker_results.push(task::try_future(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
@ -70,7 +70,7 @@ fn run(args: &[String]) {
let (to_child, from_parent) = channel();
for _ in range(0u, workers) {
let to_child = to_child.clone();
worker_results.push(task::try_future(proc() {
worker_results.push(task::try_future(move|| {
for _ in range(0u, size / workers) {
//println!("worker {}: sending {} bytes", i, num_bytes);
to_child.send(request::bytes(num_bytes));
@ -80,7 +80,7 @@ fn run(args: &[String]) {
}
from_parent
};
task::spawn(proc() {
task::spawn(move|| {
server(&from_parent, &to_parent);
});

View File

@ -89,7 +89,7 @@ fn main() {
//println!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
let new_future = Future::spawn(proc() {
let new_future = Future::spawn(move|| {
thread_ring(i, msg_per_task, num_chan_2, num_port)
});
futures.push(new_future);

View File

@ -34,7 +34,7 @@ fn ping_pong_bench(n: uint, m: uint) {
// Create a stream B->A
let (btx, brx) = channel::<()>();
spawn(proc() {
spawn(move|| {
let (tx, rx) = (atx, brx);
for _ in range(0, n) {
tx.send(());
@ -42,7 +42,7 @@ fn ping_pong_bench(n: uint, m: uint) {
}
});
spawn(proc() {
spawn(move|| {
let (tx, rx) = (btx, arx);
for _ in range(0, n) {
rx.recv();

View File

@ -21,7 +21,7 @@ fn parfib(n: uint) -> uint {
}
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
tx.send(parfib(n-1));
});
let m2 = parfib(n-2);

View File

@ -95,7 +95,7 @@ fn main() {
let mut messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
use std::num::Int;
let iterations = 2i.pow((max_depth - depth + min_depth) as uint);
Future::spawn(proc() {
Future::spawn(move|| {
let mut chk = 0;
for i in range(1, iterations + 1) {
let arena = TypedArena::new();

View File

@ -188,7 +188,7 @@ fn rendezvous(nn: uint, set: Vec<Color>) {
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (to_creature, from_rendezvous) = channel();
spawn(proc() {
spawn(move|| {
creature(ii,
col,
from_rendezvous,

View File

@ -168,7 +168,7 @@ fn fannkuch(n: i32) -> (i32, i32) {
for (i, j) in range(0, N).zip(iter::count(0, k)) {
let max = cmp::min(j+k, perm.max());
futures.push(Future::spawn(proc() {
futures.push(Future::spawn(move|| {
work(perm, j as uint, max as uint)
}))
}

View File

@ -168,7 +168,7 @@ fn main() {
let (to_child, from_parent) = channel();
spawn(proc() {
spawn(move|| {
make_sequence_processor(sz, &from_parent, &to_parent_);
});

View File

@ -303,11 +303,11 @@ fn main() {
let nb_freqs: Vec<(uint, Future<Table>)> = range(1u, 3).map(|i| {
let input = input.clone();
(i, Future::spawn(proc() generate_frequencies(input.as_slice(), i)))
(i, Future::spawn(move|| generate_frequencies(input.as_slice(), i)))
}).collect();
let occ_freqs: Vec<Future<Table>> = OCCURRENCES.iter().map(|&occ| {
let input = input.clone();
Future::spawn(proc() generate_frequencies(input.as_slice(), occ.len()))
Future::spawn(move|| generate_frequencies(input.as_slice(), occ.len()))
}).collect();
for (i, freq) in nb_freqs.into_iter() {

View File

@ -82,7 +82,7 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
let mut precalc_i = Vec::with_capacity(h);
let precalc_futures = Vec::from_fn(WORKERS, |i| {
Future::spawn(proc () {
Future::spawn(move|| {
let mut rs = Vec::with_capacity(w / WORKERS);
let mut is = Vec::with_capacity(w / WORKERS);
@ -123,7 +123,7 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
let vec_init_r = arc_init_r.clone();
let vec_init_i = arc_init_i.clone();
Future::spawn(proc () {
Future::spawn(move|| {
let mut res: Vec<u8> = Vec::with_capacity((chunk_size * w) / 8);
let init_r_slice = vec_init_r.as_slice();

View File

@ -310,7 +310,7 @@ fn par_search(masks: Vec<Vec<Vec<u64>>>) -> Data {
let masks = masks.clone();
let tx = tx.clone();
let m = *m;
spawn(proc() {
spawn(move|| {
let mut data = Data::new();
search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data);
tx.send(data);

View File

@ -34,15 +34,15 @@ fn fib(n: int) -> int {
} else {
let (tx1, rx) = channel();
let tx2 = tx1.clone();
task::spawn(proc() pfib(&tx2, n - 1));
task::spawn(move|| pfib(&tx2, n - 1));
let tx2 = tx1.clone();
task::spawn(proc() pfib(&tx2, n - 2));
task::spawn(move|| pfib(&tx2, n - 2));
tx.send(rx.recv() + rx.recv());
}
}
let (tx, rx) = channel();
spawn(proc() pfib(&tx, n) );
spawn(move|| pfib(&tx, n) );
rx.recv()
}
@ -77,7 +77,7 @@ fn stress_task(id: int) {
fn stress(num_tasks: int) {
let mut results = Vec::new();
for i in range(0, num_tasks) {
results.push(task::try_future(proc() {
results.push(task::try_future(move|| {
stress_task(i);
}));
}

View File

@ -72,7 +72,7 @@ fn main() {
let seq_arc = Arc::new(seq.clone()); // copy before it moves
let clen = seq.len();
let mut seqlen = Future::spawn(proc() {
let mut seqlen = Future::spawn(move|| {
let substs = vec![
(regex!("B"), "(c|g|t)"),
(regex!("D"), "(a|g|t)"),
@ -108,7 +108,7 @@ fn main() {
for variant in variants.into_iter() {
let seq_arc_copy = seq_arc.clone();
variant_strs.push(variant.to_string());
counts.push(Future::spawn(proc() {
counts.push(Future::spawn(move|| {
count_matches(seq_arc_copy.as_slice(), &variant)
}));
}

View File

@ -236,7 +236,7 @@ fn parallel<'a, I, T, F>(mut iter: I, f: F)
// boundary.
let f = &f as *const F as *const uint;
let raw = chunk.repr();
spawn(proc() {
spawn(move|| {
let f = f as *const F;
unsafe { (*f)(mem::transmute(raw)) }
drop(tx)

View File

@ -124,7 +124,7 @@ fn parallel<'a, T, F>(v: &'a mut [T], f: F)
// boundary.
let f = &f as *const _ as *const uint;
let raw = chunk.repr();
spawn(proc() {
spawn(move|| {
let f = f as *const F;
unsafe { (*f)(i * size, mem::transmute(raw)) }
drop(tx)

View File

@ -43,10 +43,10 @@ fn start(n_tasks: int, token: int) {
tx.send(token);
for i in range(2, n_tasks + 1) {
let (tx, next_rx) = channel();
spawn(proc() roundtrip(i, tx, rx));
spawn(move|| roundtrip(i, tx, rx));
rx = next_rx;
}
spawn(proc() roundtrip(1, tx, rx));
spawn(move|| roundtrip(1, tx, rx));
}
fn roundtrip(id: int, tx: Sender<int>, rx: Receiver<int>) {

View File

@ -10,5 +10,5 @@
// Useful for checking syscall usage of baseline scheduler usage
fn main() {
spawn(proc() {});
spawn(move|| {});
}

View File

@ -36,7 +36,7 @@ fn main() {
fn run(repeat: int, depth: int) {
for _ in range(0, repeat) {
let dur = Duration::span(|| {
task::try(proc() {
task::try(move|| {
recurse_or_panic(depth, None)
});
});

View File

@ -26,7 +26,7 @@ fn child_generation(gens_left: uint, tx: comm::Sender<()>) {
// 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,
spawn(proc() {
spawn(move|| {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
}

View File

@ -21,7 +21,7 @@ fn calc(children: uint, parent_wait_chan: &Sender<Sender<Sender<int>>>) {
let wait_ports: Vec<Reciever<Sender<Sender<int>>>> = vec::from_fn(children, |_| {
let (wait_port, wait_chan) = stream::<Sender<Sender<int>>>();
task::spawn(proc() {
task::spawn(move|| {
calc(children / 2, &wait_chan);
});
wait_port
@ -58,7 +58,7 @@ fn main() {
let children = from_str::<uint>(args[1]).unwrap();
let (wait_port, wait_chan) = stream();
task::spawn(proc() {
task::spawn(move|| {
calc(children, &wait_chan);
});

View File

@ -15,7 +15,7 @@ use std::uint;
fn f(n: uint) {
let mut i = 0u;
while i < n {
task::try(proc() g());
task::try(move|| g());
i += 1u;
}
}
@ -33,5 +33,5 @@ fn main() {
};
let n = from_str::<uint>(args[1].as_slice()).unwrap();
let mut i = 0u;
while i < n { task::spawn(proc() f(n) ); i += 1u; }
while i < n { task::spawn(move|| f(n) ); i += 1u; }
}

View File

@ -17,7 +17,7 @@ fn borrow(v: &int, f: |x: &int|) {
fn box_imm() {
let v = box 3i;
let _w = &v;
task::spawn(proc() {
task::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
@ -26,7 +26,7 @@ fn box_imm() {
fn box_imm_explicit() {
let v = box 3i;
let _w = &v;
task::spawn(proc() {
task::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move
});

View File

@ -11,6 +11,6 @@
pub fn main() {
let bar = box 3;
let _g = || {
let _h: proc() -> int = proc() *bar; //~ ERROR cannot move out of captured outer variable
let _h = move|| -> int { *bar }; //~ ERROR cannot move out of captured outer variable
};
}

View File

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn call_f(f: proc() -> int) -> int {
fn call_f<F:FnOnce() -> int>(f: F) -> int {
f()
}
fn main() {
let t = box 3;
call_f(proc() { *t + 1 });
call_f(proc() { *t + 1 }); //~ ERROR capture of moved value
call_f(move|| { *t + 1 });
call_f(move|| { *t + 1 }); //~ ERROR capture of moved value
}

View File

@ -17,7 +17,7 @@ fn different_vars_after_borrows() {
let p1 = &x1;
let x2 = box 2i;
let p2 = &x2;
task::spawn(proc() {
task::spawn(move|| {
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed
});
@ -30,7 +30,7 @@ fn different_vars_after_moves() {
drop(x1);
let x2 = box 2i;
drop(x2);
task::spawn(proc() {
task::spawn(move|| {
drop(x1); //~ ERROR capture of moved value: `x1`
drop(x2); //~ ERROR capture of moved value: `x2`
});
@ -39,7 +39,7 @@ fn different_vars_after_moves() {
fn same_var_after_borrow() {
let x = box 1i;
let p = &x;
task::spawn(proc() {
task::spawn(move|| {
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
drop(x); //~ ERROR use of moved value: `x`
});
@ -49,7 +49,7 @@ fn same_var_after_borrow() {
fn same_var_after_move() {
let x = box 1i;
drop(x);
task::spawn(proc() {
task::spawn(move|| {
drop(x); //~ ERROR capture of moved value: `x`
drop(x); //~ ERROR use of moved value: `x`
});

View File

@ -10,10 +10,10 @@
fn main() {
let x = 1i;
proc() { x = 2; };
//~^ ERROR: cannot assign to immutable captured outer variable in a proc `x`
move|:| { x = 2; };
//~^ ERROR: cannot assign to immutable captured outer variable
let s = std::io::stdin();
proc() { s.read_to_end(); };
//~^ ERROR: cannot borrow immutable captured outer variable in a proc `s` as mutable
move|:| { s.read_to_end(); };
//~^ ERROR: cannot borrow immutable captured outer variable
}

View File

@ -12,10 +12,8 @@ fn foo() {}
fn main() {
let f = foo;
let f_closure: || = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn to closure
//~^^ HELP: consider embedding the function in a closure
let f_proc: proc() = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn to closure
//~^^ HELP: consider embedding the function in a closure
}

View File

@ -10,7 +10,7 @@
fn main() {
let x = box 1i;
let f: proc() = proc() {
let f = move|:| {
let _a = x;
drop(x);
//~^ ERROR: use of moved value: `x`

View File

@ -9,10 +9,10 @@
// except according to those terms.
struct Test<'s> {
func: ||: 's,
func: Box<FnMut()+'static>
}
fn main() {
let test = box Test { func: proc() {} };
//~^ ERROR: expected `||`, found `proc()`
let closure: Box<Fn()+'static> = box || ();
let test = box Test { func: closure }; //~ ERROR mismatched types
}

View File

@ -11,7 +11,7 @@
fn main() {
let r = {
let x = box 42i;
let f = proc() &x; //~ ERROR: `x` does not live long enough
let f = move|:| &x; //~ ERROR: `x` does not live long enough
f()
};

View File

@ -10,7 +10,7 @@
fn main() {
let (tx, rx) = channel();
spawn(proc() {
spawn(move|| {
loop {
let tx = tx;
//~^ ERROR: use of moved value: `tx`

View File

@ -8,9 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn do_it(x: &int) { }
fn main() {
let f = proc() {};
(proc() {
let x = box 22;
let f = move|:| do_it(&*x);
(move|:| {
f();
f();
//~^ ERROR: use of moved value: `f`

View File

@ -13,14 +13,10 @@ use std::rc::Rc;
fn foo(_x: Rc<uint>) {}
fn bar() {
fn bar<F:FnOnce() + Send>(_: F) { }
fn main() {
let x = Rc::new(3u);
let _: proc():Send = proc() foo(x); //~ ERROR `core::kinds::Send` is not implemented
bar(move|| foo(x)); //~ ERROR `core::kinds::Send` is not implemented
}
fn bar2() {
let x = Rc::new(3u);
let _: proc() = proc() foo(x);
}
fn main() { }

View File

@ -27,10 +27,6 @@ fn box_object_with_no_bound_not_ok<'a>() {
assert_send::<Box<Dummy>>(); //~ ERROR the trait `core::kinds::Send` is not implemented
}
fn proc_with_no_bound_not_ok<'a>() {
assert_send::<proc()>(); //~ ERROR the trait `core::kinds::Send` is not implemented
}
fn closure_with_no_bound_not_ok<'a>() {
assert_send::<||:'static>(); //~ ERROR the trait `core::kinds::Send` is not implemented
}
@ -38,7 +34,6 @@ fn closure_with_no_bound_not_ok<'a>() {
fn object_with_send_bound_ok() {
assert_send::<&'static (Dummy+Send)>();
assert_send::<Box<Dummy+Send>>();
assert_send::<proc():Send>;
assert_send::<||:Send>;
}

View File

@ -35,11 +35,6 @@ fn test61() {
// closure and object types can have lifetime bounds which make
// them not ok
fn test_70<'a>() {
assert_send::<proc():'a>();
//~^ ERROR the trait `core::kinds::Send` is not implemented
}
fn test_71<'a>() {
assert_send::<Box<Dummy+'a>>();
//~^ ERROR the trait `core::kinds::Send` is not implemented

View File

@ -12,7 +12,7 @@ use std::task;
fn main() {
let x = "Hello world!".to_string();
task::spawn(proc() {
task::spawn(move|| {
println!("{}", x);
});
println!("{}", x); //~ ERROR use of moved value

View File

@ -9,7 +9,7 @@
// except according to those terms.
type Noncopyable = proc():'static;
type Noncopyable = Box<int>;
struct Foo {
copied: int,

View File

@ -17,7 +17,7 @@ fn main() {
let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
task::spawn(proc() {
task::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});

View File

@ -15,7 +15,7 @@ fn main() {
let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
task::spawn(proc() {
task::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});

View File

@ -35,9 +35,9 @@ fn main() {
let x = foo(Port(Rc::new(())));
task::spawn(proc() {
let y = x;
task::spawn(move|| {
//~^ ERROR `core::kinds::Send` is not implemented
let y = x;
println!("{}", y);
});
}

View File

@ -14,14 +14,14 @@
#![feature(once_fns)]
use std::sync::Arc;
fn foo(blk: proc()) {
fn foo<F:FnOnce()>(blk: F) {
blk();
blk(); //~ ERROR use of moved value
}
fn main() {
let x = Arc::new(true);
foo(proc() {
foo(move|| {
assert!(*x);
drop(x);
});

View File

@ -66,11 +66,6 @@ fn object_with_send_bound_not_ok<'a>() {
//~^ ERROR declared lifetime bound not satisfied
}
fn proc_with_lifetime_not_ok<'a>() {
assert_send::<proc():'a>();
//~^ ERROR not implemented
}
fn closure_with_lifetime_not_ok<'a>() {
assert_send::<||:'a>();
//~^ ERROR not implemented

View File

@ -11,14 +11,14 @@
// Test that, when a variable of type `&T` is captured inside a proc,
// we correctly infer/require that its lifetime is 'static.
fn foo(_p: proc():'static) { }
fn foo<F:FnOnce()+'static>(_p: F) { }
static i: int = 3;
fn capture_local() {
let x = 3i;
let y = &x; //~ ERROR `x` does not live long enough
foo(proc() {
foo(move|| {
let _a = *y;
});
}
@ -26,7 +26,7 @@ fn capture_local() {
fn capture_static() {
// Legal because &i can have static lifetime:
let y = &i;
foo(proc() {
foo(move|| {
let _a = *y;
});
}

View File

@ -8,19 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn borrowed_proc<'a>(x: &'a int) -> proc():'a -> int {
fn borrowed_proc<'a>(x: &'a int) -> Box<FnMut()->(int) + 'a> {
// This is legal, because the region bound on `proc`
// states that it captures `x`.
proc() {
*x
}
box move|| { *x }
}
fn static_proc<'a>(x: &'a int) -> proc():'static -> int {
fn static_proc(x: &int) -> Box<FnMut()->(int) + 'static> {
// This is illegal, because the region bound on `proc` is 'static.
proc() { //~ ERROR captured variable `x` outlives the `proc()`
*x
}
box move|| { *x } //~ ERROR cannot infer
}
fn main() { }

View File

@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: mismatched types
use std::task;
fn main() { task::spawn(|| -> int { 10 }); }
fn main() {
// We get an error because return type is `->int` and not `->()`.
task::spawn(|| -> int { 10 });
//~^ ERROR type mismatch
}

View File

@ -0,0 +1,25 @@
// Copyright 2014 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.
// Check that parenthetical notation is feature-gated except with the
// `Fn` traits.
trait Foo<A,R> {
}
fn main() {
let x: Box<Foo(int)>;
//~^ ERROR parenthetical notation is only stable when used with the `Fn` family
// No errors with these:
let x: Box<Fn(int)>;
let x: Box<FnMut(int)>;
let x: Box<FnOnce(int)>;
}

View File

@ -12,6 +12,6 @@
fn main() {
let mut_ = |&mut: x| x;
mut_.call((0i, )); //~ ERROR type `closure` does not implement
mut_.call((0i, )); //~ ERROR does not implement any method in scope named `call`
}

View File

@ -13,5 +13,5 @@
fn main() {
let mut x = 1i;
//~^ ERROR: variable does not need to be mutable
proc() { println!("{}", x); };
move|:| { println!("{}", x); };
}

View File

@ -77,7 +77,7 @@ fn main() {
zzz(); // #break
sentinel();
let unique_closure: proc(int) = proc(x) {
let unique_closure = |: x:int| {
zzz(); // #break
sentinel();

View File

@ -167,9 +167,6 @@
// CLOSURES
// gdb-command:whatis some_proc
// gdb-check:type = struct (once proc(int, u8) -> (int, u8), uint)
// gdb-command:whatis stack_closure1
// gdb-check:type = struct (&mut|int|, uint)
@ -322,8 +319,6 @@ fn main() {
// how that maps to rustc's internal representation of these forms.
// Once closures have reached their 1.0 form, the tests below should
// probably be expanded.
let some_proc = (proc(a:int, b:u8) (a, b), 0u);
let stack_closure1 = (|x:int| {}, 0u);
let stack_closure2 = (|x:i8, y: f32| { (x as f32) + y }, 0u);

View File

@ -13,7 +13,7 @@
// pp-exact
fn call_it(f: proc(String) -> String) { }
fn call_it(f: Box<FnMut(String) -> String>) { }
fn call_this(f: |&str|: Send) { }

Some files were not shown because too many files have changed in this diff Show More