From 6fa16d6a473415415cb87a1fe6754aace32cbb1c Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 13 Apr 2015 10:21:32 -0400 Subject: pluralize doc comment verbs and add missing periods --- src/libstd/thread/local.rs | 2 +- src/libstd/thread/mod.rs | 36 ++++++++++++++++++------------------ src/libstd/thread/scoped_tls.rs | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src/libstd/thread') diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index f5a1093be2b..cc4031cc180 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -226,7 +226,7 @@ pub enum LocalKeyState { } impl LocalKey { - /// Acquire a reference to the value in this TLS key. + /// Acquires a reference to the value in this TLS key. /// /// This will lazily initialize the value if this thread has not referenced /// this key yet. diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 0e5fee27ffe..5db7e9773c9 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -215,7 +215,7 @@ pub struct Builder { } impl Builder { - /// Generate the base configuration for spawning a thread, from which + /// Generates the base configuration for spawning a thread, from which /// configuration methods can be chained. #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> Builder { @@ -225,7 +225,7 @@ impl Builder { } } - /// Name the thread-to-be. Currently the name is used for identification + /// Names the thread-to-be. Currently the name is used for identification /// only in panic messages. #[stable(feature = "rust1", since = "1.0.0")] pub fn name(mut self, name: String) -> Builder { @@ -233,14 +233,14 @@ impl Builder { self } - /// Set the size of the stack for the new thread. + /// Sets the size of the stack for the new thread. #[stable(feature = "rust1", since = "1.0.0")] pub fn stack_size(mut self, size: usize) -> Builder { self.stack_size = Some(size); self } - /// Spawn a new thread, and return a join handle for it. + /// Spawns a new thread, and returns a join handle for it. /// /// The child thread may outlive the parent (unless the parent thread /// is the main thread; the whole process is terminated when the main @@ -259,8 +259,8 @@ impl Builder { self.spawn_inner(Box::new(f)).map(|i| JoinHandle(i)) } - /// Spawn a new child thread that must be joined within a given - /// scope, and return a `JoinGuard`. + /// Spawns a new child thread that must be joined within a given + /// scope, and returns a `JoinGuard`. /// /// The join guard can be used to explicitly join the child thread (via /// `join`), returning `Result`, or it will implicitly join the child @@ -355,7 +355,7 @@ impl Builder { // Free functions //////////////////////////////////////////////////////////////////////////////// -/// Spawn a new thread, returning a `JoinHandle` for it. +/// Spawns a new thread, returning a `JoinHandle` for it. /// /// The join handle will implicitly *detach* the child thread upon being /// dropped. In this case, the child thread may outlive the parent (unless @@ -374,7 +374,7 @@ pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { Builder::new().spawn(f).unwrap() } -/// Spawn a new *scoped* thread, returning a `JoinGuard` for it. +/// Spawns a new *scoped* thread, returning a `JoinGuard` for it. /// /// The join guard can be used to explicitly join the child thread (via /// `join`), returning `Result`, or it will implicitly join the child @@ -400,7 +400,7 @@ pub fn current() -> Thread { thread_info::current_thread() } -/// Cooperatively give up a timeslice to the OS scheduler. +/// Cooperatively gives up a timeslice to the OS scheduler. #[stable(feature = "rust1", since = "1.0.0")] pub fn yield_now() { unsafe { imp::yield_now() } @@ -413,7 +413,7 @@ pub fn panicking() -> bool { unwind::panicking() } -/// Invoke a closure, capturing the cause of panic if one occurs. +/// Invokes a closure, capturing the cause of panic if one occurs. /// /// This function will return `Ok(())` if the closure does not panic, and will /// return `Err(cause)` if the closure panics. The `cause` returned is the @@ -462,7 +462,7 @@ pub fn catch_panic(f: F) -> Result Ok(result.unwrap()) } -/// Put the current thread to sleep for the specified amount of time. +/// Puts the current thread to sleep for the specified amount of time. /// /// The thread may sleep longer than the duration specified due to scheduling /// specifics or platform-dependent functionality. Note that on unix platforms @@ -482,7 +482,7 @@ pub fn sleep(dur: Duration) { imp::sleep(dur) } -/// Block unless or until the current thread's token is made available (may wake spuriously). +/// Blocks unless or until the current thread's token is made available (may wake spuriously). /// /// See the module doc for more detail. // @@ -501,7 +501,7 @@ pub fn park() { *guard = false; } -/// Block unless or until the current thread's token is made available or +/// Blocks unless or until the current thread's token is made available or /// the specified duration has been reached (may wake spuriously). /// /// The semantics of this function are equivalent to `park()` except that the @@ -573,7 +573,7 @@ impl Thread { } } - /// Get the thread's name. + /// Gets the thread's name. #[stable(feature = "rust1", since = "1.0.0")] pub fn name(&self) -> Option<&str> { self.inner.name.as_ref().map(|s| &**s) @@ -638,13 +638,13 @@ impl JoinInner { pub struct JoinHandle(JoinInner<()>); impl JoinHandle { - /// Extract a handle to the underlying thread + /// Extracts a handle to the underlying thread #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { &self.0.thread } - /// Wait for the associated thread to finish. + /// Waits for the associated thread to finish. /// /// If the child thread panics, `Err` is returned with the parameter given /// to `panic`. @@ -684,13 +684,13 @@ pub struct JoinGuard<'a, T: Send + 'a> { unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} impl<'a, T: Send + 'a> JoinGuard<'a, T> { - /// Extract a handle to the thread this guard will join on. + /// Extracts a handle to the thread this guard will join on. #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { &self.inner.thread } - /// Wait for the associated thread to finish, returning the result of the + /// Waits for the associated thread to finish, returning the result of the /// thread's calculation. /// /// # Panics diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs index fa980954c2f..9c0b4a5d833 100644 --- a/src/libstd/thread/scoped_tls.rs +++ b/src/libstd/thread/scoped_tls.rs @@ -135,7 +135,7 @@ macro_rules! __scoped_thread_local_inner { reason = "scoped TLS has yet to have wide enough use to fully consider \ stabilizing its interface")] impl ScopedKey { - /// Insert a value into this scoped thread local storage slot for a + /// Inserts a value into this scoped thread local storage slot for a /// duration of a closure. /// /// While `cb` is running, the value `t` will be returned by `get` unless @@ -188,7 +188,7 @@ impl ScopedKey { cb() } - /// Get a value out of this scoped variable. + /// Gets a value out of this scoped variable. /// /// This function takes a closure which receives the value of this /// variable. -- cgit 1.4.1-3-g733a5 From 6399bb425b3a82111cd554737f194c95b8f6bad5 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 13 Apr 2015 12:08:20 -0700 Subject: De-stabilize `thread::scoped` and friends Issue #24292 demonstrates that the `scoped` API as currently offered can be memory-unsafe: the `JoinGuard` can be moved into a context that will fail to execute destructors prior to the stack frame being popped (for example, by creating an `Rc` cycle). This commit reverts the APIs to `unstable` status while a long-term solution is worked out. (There are several possible ways to address this issue; it's not a fundamental problem with the `scoped` idea, but rather an indication that Rust doesn't currently provide a good way to ensure that destructors are run within a particular stack frame.) [breaking-change] --- src/libstd/thread/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/libstd/thread') diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 0e5fee27ffe..23991102650 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -274,7 +274,8 @@ impl Builder { /// Unlike the `scoped` free function, this method yields an /// `io::Result` to capture any failure to create the thread at /// the OS level. - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "scoped", + reason = "memory unsafe if destructor is avoided, see #24292")] pub fn scoped<'a, T, F>(self, f: F) -> io::Result> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { @@ -387,7 +388,8 @@ pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { /// /// Panics if the OS fails to create a thread; use `Builder::scoped` /// to recover from such errors. -#[stable(feature = "rust1", since = "1.0.0")] +#[unstable(feature = "scoped", + reason = "memory unsafe if destructor is avoided, see #24292")] pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { @@ -674,7 +676,8 @@ impl Drop for JoinHandle { /// handle: the ability to join a child thread is a uniquely-owned /// permission. #[must_use = "thread will be immediately joined if `JoinGuard` is not used"] -#[stable(feature = "rust1", since = "1.0.0")] +#[unstable(feature = "scoped", + reason = "memory unsafe if destructor is avoided, see #24292")] pub struct JoinGuard<'a, T: Send + 'a> { inner: JoinInner, _marker: PhantomData<&'a T>, @@ -706,7 +709,8 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { } #[unsafe_destructor] -#[stable(feature = "rust1", since = "1.0.0")] +#[unstable(feature = "scoped", + reason = "memory unsafe if destructor is avoided, see #24292")] impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { fn drop(&mut self) { if !self.inner.joined { -- cgit 1.4.1-3-g733a5 From 6e0fb70ff6effe7b7be2c5fe951e9161613e6707 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 13 Apr 2015 14:48:17 -0700 Subject: Generalize `spawn` beyond unit closures `thread::spawn` was previously restricted to closures that return `()`, which limited the utility of joining on a spawned thread. However, there is no reason for this restriction, and this commit allows arbitrary return types. Since it introduces a type parameter to `JoinHandle`, it's technically a: [breaking-change] However, no code is actually expected to break. --- src/libstd/thread/mod.rs | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'src/libstd/thread') diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 23991102650..29fcd155283 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -67,11 +67,30 @@ //! thread. This means that it can outlive its parent (the thread that spawned //! it), unless this parent is the main thread. //! +//! The parent thread can also wait on the completion of the child +//! thread; a call to `spawn` produces a `JoinHandle`, which provides +//! a `join` method for waiting: +//! +//! ```rust +//! use std::thread; +//! +//! let child = thread::spawn(move || { +//! // some work here +//! }); +//! // some work here +//! let res = child.join(); +//! ``` +//! +//! The `join` method returns a `Result` containing `Ok` of the final +//! value produced by the child thread, or `Err` of the value given to +//! a call to `panic!` if the child panicked. +//! //! ## Scoped threads //! -//! Often a parent thread uses a child thread to perform some particular task, -//! and at some point must wait for the child to complete before continuing. -//! For this scenario, use the `thread::scoped` function: +//! The `spawn` method does not allow the child and parent threads to +//! share any stack data, since that is not safe in general. However, +//! `scoped` makes it possible to share the parent's stack by forcing +//! a join before any relevant stack frames are popped: //! //! ```rust //! use std::thread; @@ -253,8 +272,8 @@ impl Builder { /// `io::Result` to capture any failure to create the thread at /// the OS level. #[stable(feature = "rust1", since = "1.0.0")] - pub fn spawn(self, f: F) -> io::Result where - F: FnOnce(), F: Send + 'static + pub fn spawn(self, f: F) -> io::Result> where + F: FnOnce() -> T, F: Send + 'static, T: Send + 'static { self.spawn_inner(Box::new(f)).map(|i| JoinHandle(i)) } @@ -371,7 +390,9 @@ impl Builder { /// Panics if the OS fails to create a thread; use `Builder::spawn` /// to recover from such errors. #[stable(feature = "rust1", since = "1.0.0")] -pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { +pub fn spawn(f: F) -> JoinHandle where + F: FnOnce() -> T, F: Send + 'static, T: Send + 'static +{ Builder::new().spawn(f).unwrap() } @@ -637,9 +658,9 @@ impl JoinInner { /// handle: the ability to join a child thread is a uniquely-owned /// permission. #[stable(feature = "rust1", since = "1.0.0")] -pub struct JoinHandle(JoinInner<()>); +pub struct JoinHandle(JoinInner); -impl JoinHandle { +impl JoinHandle { /// Extract a handle to the underlying thread #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { @@ -651,13 +672,14 @@ impl JoinHandle { /// If the child thread panics, `Err` is returned with the parameter given /// to `panic`. #[stable(feature = "rust1", since = "1.0.0")] - pub fn join(mut self) -> Result<()> { + pub fn join(mut self) -> Result { self.0.join() } } #[stable(feature = "rust1", since = "1.0.0")] -impl Drop for JoinHandle { +#[unsafe_destructor] +impl Drop for JoinHandle { fn drop(&mut self) { if !self.0.joined { unsafe { imp::detach(self.0.native) } -- cgit 1.4.1-3-g733a5 From a9fd41e1f984fdfecb78ba9570bb159854c58b16 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 13 Apr 2015 15:15:32 -0700 Subject: Fallout: move from scoped to spawn --- src/doc/intro.md | 4 ++ src/doc/trpl/concurrency.md | 49 ++++------------------ src/librustdoc/lib.rs | 4 +- src/libstd/thread/mod.rs | 1 + src/test/bench/shootout-binarytrees.rs | 4 +- src/test/bench/shootout-fannkuch-redux.rs | 4 +- src/test/bench/shootout-k-nucleotide.rs | 8 ++-- src/test/bench/shootout-mandelbrot.rs | 8 ++-- src/test/bench/shootout-reverse-complement.rs | 2 +- src/test/bench/shootout-spectralnorm.rs | 2 +- src/test/run-fail/panic-task-name-owned.rs | 4 +- src/test/run-fail/rt-set-exit-status-panic2.rs | 2 +- src/test/run-pass/atomic-print.rs | 2 +- src/test/run-pass/capturing-logging.rs | 3 +- src/test/run-pass/clone-with-exterior.rs | 4 +- src/test/run-pass/comm.rs | 3 +- src/test/run-pass/extern-call-deep2.rs | 2 +- src/test/run-pass/extern-call-scrub.rs | 4 +- src/test/run-pass/fds-are-cloexec.rs | 7 +--- src/test/run-pass/init-large-type.rs | 2 +- src/test/run-pass/issue-13494.rs | 3 +- src/test/run-pass/issue-20454.rs | 4 +- src/test/run-pass/issue-3609.rs | 4 +- src/test/run-pass/issue-9396.rs | 3 +- src/test/run-pass/ivec-tag.rs | 3 +- .../run-pass/kindck-implicit-close-over-mut-var.rs | 11 +++-- .../run-pass/moves-based-on-type-capture-clause.rs | 4 +- .../run-pass/out-of-stack-new-thread-no-split.rs | 2 +- src/test/run-pass/rust-log-filter.rs | 4 +- src/test/run-pass/send-is-not-static-par-for.rs | 3 +- src/test/run-pass/send-resource.rs | 4 +- src/test/run-pass/spawn-fn.rs | 9 ++-- src/test/run-pass/task-comm-0.rs | 3 +- src/test/run-pass/task-comm-1.rs | 2 +- src/test/run-pass/task-comm-10.rs | 4 +- src/test/run-pass/task-comm-11.rs | 3 +- src/test/run-pass/task-comm-12.rs | 2 +- src/test/run-pass/task-comm-13.rs | 2 +- src/test/run-pass/task-comm-14.rs | 2 +- src/test/run-pass/task-comm-15.rs | 3 +- src/test/run-pass/task-comm-17.rs | 2 +- src/test/run-pass/task-comm-3.rs | 2 +- src/test/run-pass/task-comm-7.rs | 13 ++++-- src/test/run-pass/task-comm-9.rs | 2 +- src/test/run-pass/task-life-0.rs | 2 +- src/test/run-pass/task-spawn-move-and-copy.rs | 4 +- src/test/run-pass/tcp-accept-stress.rs | 9 ++-- src/test/run-pass/tcp-connect-timeouts.rs | 3 +- src/test/run-pass/tempfile.rs | 4 +- src/test/run-pass/threads.rs | 2 +- src/test/run-pass/trait-bounds-in-arc.rs | 9 ++-- src/test/run-pass/unique-send-2.rs | 6 ++- 52 files changed, 128 insertions(+), 124 deletions(-) (limited to 'src/libstd/thread') diff --git a/src/doc/intro.md b/src/doc/intro.md index 1dc9f09c220..e6d560d8122 100644 --- a/src/doc/intro.md +++ b/src/doc/intro.md @@ -389,6 +389,7 @@ safe concurrent programs. Here's an example of a concurrent Rust program: ```{rust} +# #![feature(scoped)] use std::thread; fn main() { @@ -421,6 +422,7 @@ problem. Let's see an example. This Rust code will not compile: ```{rust,ignore} +# #![feature(scoped)] use std::thread; fn main() { @@ -467,6 +469,7 @@ that our mutation doesn't cause a data race. Here's what using a Mutex looks like: ```{rust} +# #![feature(scoped)] use std::thread; use std::sync::Mutex; @@ -527,6 +530,7 @@ As an example, Rust's ownership system is _entirely_ at compile time. The safety check that makes this an error about moved values: ```{rust,ignore} +# #![feature(scoped)] use std::thread; fn main() { diff --git a/src/doc/trpl/concurrency.md b/src/doc/trpl/concurrency.md index f9358f28b01..159e04e9429 100644 --- a/src/doc/trpl/concurrency.md +++ b/src/doc/trpl/concurrency.md @@ -56,68 +56,35 @@ place! ## Threads -Rust's standard library provides a library for 'threads', which allow you to +Rust's standard library provides a library for threads, which allow you to run Rust code in parallel. Here's a basic example of using `std::thread`: ``` use std::thread; fn main() { - thread::scoped(|| { + thread::spawn(|| { println!("Hello from a thread!"); }); } ``` -The `thread::scoped()` method accepts a closure, which is executed in a new -thread. It's called `scoped` because this thread returns a join guard: +The `thread::spawn()` method accepts a closure, which is executed in a +new thread. It returns a handle to the thread, that can be used to +wait for the child thread to finish and extract its result: ``` use std::thread; fn main() { - let guard = thread::scoped(|| { - println!("Hello from a thread!"); + let handle = thread::spawn(|| { + "Hello from a thread!" }); - // guard goes out of scope here + println!("{}", handle.join().unwrap()); } ``` -When `guard` goes out of scope, it will block execution until the thread is -finished. If we didn't want this behaviour, we could use `thread::spawn()`: - -``` -use std::thread; - -fn main() { - thread::spawn(|| { - println!("Hello from a thread!"); - }); - - thread::sleep_ms(50); -} -``` - -We need to `sleep` here because when `main()` ends, it kills all of the -running threads. - -[`scoped`](std/thread/struct.Builder.html#method.scoped) has an interesting -type signature: - -```text -fn scoped<'a, T, F>(self, f: F) -> JoinGuard<'a, T> - where T: Send + 'a, - F: FnOnce() -> T, - F: Send + 'a -``` - -Specifically, `F`, the closure that we pass to execute in the new thread. It -has two restrictions: It must be a `FnOnce` from `()` to `T`. Using `FnOnce` -allows the closure to take ownership of any data it mentions from the parent -thread. The other restriction is that `F` must be `Send`. We aren't allowed to -transfer this ownership unless the type thinks that's okay. - Many languages have the ability to execute threads, but it's wildly unsafe. There are entire books about how to prevent errors that occur from shared mutable state. Rust helps out with its type system here as well, by preventing diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index bdee53cd009..1393c39f66c 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -130,10 +130,10 @@ struct Output { pub fn main() { const STACK_SIZE: usize = 32000000; // 32MB - let res = std::thread::Builder::new().stack_size(STACK_SIZE).scoped(move || { + let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || { let s = env::args().collect::>(); main_args(&s) - }).unwrap().join(); + }).unwrap().join().unwrap(); env::set_exit_status(res as i32); } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 29fcd155283..90ef94bb6e1 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -93,6 +93,7 @@ //! a join before any relevant stack frames are popped: //! //! ```rust +//! # #![feature(scoped)] //! use std::thread; //! //! let guard = thread::scoped(move || { diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index ce050cc7323..61fe6593dc3 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -111,11 +111,11 @@ fn main() { let messages = (min_depth..max_depth + 1).step_by(2).map(|depth| { use std::num::Int; let iterations = 2.pow((max_depth - depth + min_depth) as u32); - thread::scoped(move || inner(depth, iterations)) + thread::spawn(move || inner(depth, iterations)) }).collect::>(); for message in messages { - println!("{}", message.join()); + println!("{}", message.join().unwrap()); } println!("long lived tree of depth {}\t check: {}", diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 4489a124abe..32504350e42 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -166,7 +166,7 @@ fn fannkuch(n: i32) -> (i32, i32) { for (_, j) in (0..N).zip((0..).step_by(k)) { let max = cmp::min(j+k, perm.max()); - futures.push(thread::scoped(move|| { + futures.push(thread::spawn(move|| { work(perm, j as usize, max as usize) })) } @@ -174,7 +174,7 @@ fn fannkuch(n: i32) -> (i32, i32) { let mut checksum = 0; let mut maxflips = 0; for fut in futures { - let (cs, mf) = fut.join(); + let (cs, mf) = fut.join().unwrap(); checksum += cs; maxflips = cmp::max(maxflips, mf); } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index db131bcfdc3..07cb120ef0e 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -307,17 +307,17 @@ fn main() { let nb_freqs: Vec<_> = (1..3).map(|i| { let input = input.clone(); - (i, thread::scoped(move|| generate_frequencies(&input, i))) + (i, thread::spawn(move|| generate_frequencies(&input, i))) }).collect(); let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| { let input = input.clone(); - thread::scoped(move|| generate_frequencies(&input, occ.len())) + thread::spawn(move|| generate_frequencies(&input, occ.len())) }).collect(); for (i, freq) in nb_freqs { - print_frequencies(&freq.join(), i); + print_frequencies(&freq.join().unwrap(), i); } for (&occ, freq) in OCCURRENCES.iter().zip(occ_freqs.into_iter()) { - print_occurrences(&mut freq.join(), occ); + print_occurrences(&mut freq.join().unwrap(), occ); } } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index d248293103b..bf41838bfa7 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -82,7 +82,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let mut precalc_i = Vec::with_capacity(h); let precalc_futures = (0..WORKERS).map(|i| { - thread::scoped(move|| { + thread::spawn(move|| { let mut rs = Vec::with_capacity(w / WORKERS); let mut is = Vec::with_capacity(w / WORKERS); @@ -108,7 +108,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { }).collect::>(); for res in precalc_futures { - let (rs, is) = res.join(); + let (rs, is) = res.join().unwrap(); precalc_r.extend(rs.into_iter()); precalc_i.extend(is.into_iter()); } @@ -123,7 +123,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let vec_init_r = arc_init_r.clone(); let vec_init_i = arc_init_i.clone(); - thread::scoped(move|| { + thread::spawn(move|| { let mut res: Vec = Vec::with_capacity((chunk_size * w) / 8); let init_r_slice = vec_init_r; @@ -144,7 +144,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { try!(writeln!(&mut out as &mut Writer, "P4\n{} {}", w, h)); for res in data { - try!(out.write(&res.join())); + try!(out.write(&res.join().unwrap())); } out.flush() } diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index cda90c08f23..e200682acfd 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -40,7 +40,7 @@ // ignore-android see #10393 #13206 -#![feature(unboxed_closures, libc, old_io, collections, io, core)] +#![feature(unboxed_closures, libc, old_io, collections, io, core, scoped)] extern crate libc; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 5fcbe773299..b0e8c395673 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -41,7 +41,7 @@ // no-pretty-expanded FIXME #15189 #![allow(non_snake_case)] -#![feature(unboxed_closures, core, os)] +#![feature(unboxed_closures, core, os, scoped)] use std::iter::repeat; use std::thread; diff --git a/src/test/run-fail/panic-task-name-owned.rs b/src/test/run-fail/panic-task-name-owned.rs index 8cab9e05f96..561f141100c 100644 --- a/src/test/run-fail/panic-task-name-owned.rs +++ b/src/test/run-fail/panic-task-name-owned.rs @@ -13,9 +13,9 @@ use std::thread::Builder; fn main() { - let r: () = Builder::new().name("owned name".to_string()).scoped(move|| { + let r: () = Builder::new().name("owned name".to_string()).spawn(move|| { panic!("test"); () - }).unwrap().join(); + }).unwrap().join().unwrap(); panic!(); } diff --git a/src/test/run-fail/rt-set-exit-status-panic2.rs b/src/test/run-fail/rt-set-exit-status-panic2.rs index fddff3c5a9f..b4f0d7ceb99 100644 --- a/src/test/run-fail/rt-set-exit-status-panic2.rs +++ b/src/test/run-fail/rt-set-exit-status-panic2.rs @@ -37,7 +37,7 @@ fn r(x:isize) -> r { fn main() { error!("whatever"); - let _t = thread::scoped(move|| { + let _t = thread::spawn(move|| { let _i = r(5); }); panic!(); diff --git a/src/test/run-pass/atomic-print.rs b/src/test/run-pass/atomic-print.rs index df3b572bce4..ae0a358ac4e 100644 --- a/src/test/run-pass/atomic-print.rs +++ b/src/test/run-pass/atomic-print.rs @@ -27,7 +27,7 @@ fn main(){ if env::args().count() == 2 { let barrier = sync::Arc::new(sync::Barrier::new(2)); let tbarrier = barrier.clone(); - let t = thread::scoped(||{ + let t = thread::spawn(move || { tbarrier.wait(); do_print(1); }); diff --git a/src/test/run-pass/capturing-logging.rs b/src/test/run-pass/capturing-logging.rs index f9b429a935a..f7e8edca440 100644 --- a/src/test/run-pass/capturing-logging.rs +++ b/src/test/run-pass/capturing-logging.rs @@ -36,7 +36,7 @@ impl Logger for MyWriter { fn main() { let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { set_logger(box MyWriter(w) as Box); debug!("debug"); info!("info"); @@ -44,4 +44,5 @@ fn main() { let s = r.read_to_string().unwrap(); assert!(s.contains("info")); assert!(!s.contains("debug")); + t.join(); } diff --git a/src/test/run-pass/clone-with-exterior.rs b/src/test/run-pass/clone-with-exterior.rs index 16efceb9d7e..ef2796243c8 100644 --- a/src/test/run-pass/clone-with-exterior.rs +++ b/src/test/run-pass/clone-with-exterior.rs @@ -23,8 +23,8 @@ struct Pair { pub fn main() { let z: Box<_> = box Pair { a : 10, b : 12}; - let _t = thread::scoped(move|| { + thread::spawn(move|| { assert_eq!(z.a, 10); assert_eq!(z.b, 12); - }); + }).join(); } diff --git a/src/test/run-pass/comm.rs b/src/test/run-pass/comm.rs index 859599596ae..72f623ccfde 100644 --- a/src/test/run-pass/comm.rs +++ b/src/test/run-pass/comm.rs @@ -15,11 +15,12 @@ use std::sync::mpsc::{channel, Sender}; pub fn main() { let (tx, rx) = channel(); - let _t = thread::scoped(move|| { child(&tx) }); + let t = thread::spawn(move|| { child(&tx) }); let y = rx.recv().unwrap(); println!("received"); println!("{}", y); assert_eq!(y, 10); + t.join(); } fn child(c: &Sender) { diff --git a/src/test/run-pass/extern-call-deep2.rs b/src/test/run-pass/extern-call-deep2.rs index 198745f5b19..b35095171ec 100644 --- a/src/test/run-pass/extern-call-deep2.rs +++ b/src/test/run-pass/extern-call-deep2.rs @@ -42,7 +42,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t { pub fn main() { // Make sure we're on a task with small Rust stacks (main currently // has a large stack) - thread::scoped(move|| { + thread::spawn(move|| { let result = count(1000); println!("result = {}", result); assert_eq!(result, 1000); diff --git a/src/test/run-pass/extern-call-scrub.rs b/src/test/run-pass/extern-call-scrub.rs index e8c9bc76335..39938680681 100644 --- a/src/test/run-pass/extern-call-scrub.rs +++ b/src/test/run-pass/extern-call-scrub.rs @@ -46,9 +46,9 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t { pub fn main() { // Make sure we're on a task with small Rust stacks (main currently // has a large stack) - let _t = thread::scoped(move|| { + thread::spawn(move|| { let result = count(12); println!("result = {}", result); assert_eq!(result, 2048); - }); + }).join(); } diff --git a/src/test/run-pass/fds-are-cloexec.rs b/src/test/run-pass/fds-are-cloexec.rs index cbf7830513a..3be47e8430d 100644 --- a/src/test/run-pass/fds-are-cloexec.rs +++ b/src/test/run-pass/fds-are-cloexec.rs @@ -34,14 +34,12 @@ fn main() { fn parent() { let file = File::open("Makefile").unwrap(); - let _dir = fs::read_dir("/").unwrap(); let tcp1 = TcpListener::bind("127.0.0.1:0").unwrap(); - assert_eq!(tcp1.as_raw_fd(), file.as_raw_fd() + 2); let tcp2 = tcp1.try_clone().unwrap(); let addr = tcp1.local_addr().unwrap(); - let t = thread::scoped(|| TcpStream::connect(addr).unwrap()); + let t = thread::spawn(move || TcpStream::connect(addr).unwrap()); let tcp3 = tcp1.accept().unwrap().0; - let tcp4 = t.join(); + let tcp4 = t.join().unwrap(); let tcp5 = tcp3.try_clone().unwrap(); let tcp6 = tcp4.try_clone().unwrap(); let udp1 = UdpSocket::bind("127.0.0.1:0").unwrap(); @@ -49,7 +47,6 @@ fn parent() { let status = Command::new(env::args().next().unwrap()) .arg(file.as_raw_fd().to_string()) - .arg((file.as_raw_fd() + 1).to_string()) .arg(tcp1.as_raw_fd().to_string()) .arg(tcp2.as_raw_fd().to_string()) .arg(tcp3.as_raw_fd().to_string()) diff --git a/src/test/run-pass/init-large-type.rs b/src/test/run-pass/init-large-type.rs index 26d58d34b9d..dafa8ee1033 100644 --- a/src/test/run-pass/init-large-type.rs +++ b/src/test/run-pass/init-large-type.rs @@ -26,7 +26,7 @@ const SIZE: usize = 1024 * 1024; fn main() { // do the test in a new thread to avoid (spurious?) stack overflows - let _ = thread::scoped(|| { + thread::spawn(|| { let _memory: [u8; SIZE] = unsafe { init() }; }).join(); } diff --git a/src/test/run-pass/issue-13494.rs b/src/test/run-pass/issue-13494.rs index d1b1647de78..71897ea68c2 100644 --- a/src/test/run-pass/issue-13494.rs +++ b/src/test/run-pass/issue-13494.rs @@ -26,7 +26,7 @@ fn helper(rx: Receiver>) { fn main() { let (tx, rx) = channel(); - let _t = thread::scoped(move|| { helper(rx) }); + let t = thread::spawn(move|| { helper(rx) }); let (snd, rcv) = channel::(); for _ in 1..100000 { snd.send(1).unwrap(); @@ -38,4 +38,5 @@ fn main() { } } drop(tx); + t.join(); } diff --git a/src/test/run-pass/issue-20454.rs b/src/test/run-pass/issue-20454.rs index d527d9519cf..522f544a21c 100644 --- a/src/test/run-pass/issue-20454.rs +++ b/src/test/run-pass/issue-20454.rs @@ -13,11 +13,11 @@ use std::thread; fn _foo() { - let _t = thread::scoped(move || { // no need for -> () + thread::spawn(move || { // no need for -> () loop { println!("hello"); } - }); + }).join(); } fn main() {} diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index 2167a3df976..61de3c6385e 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -23,7 +23,7 @@ enum Msg } fn foo(name: String, samples_chan: Sender) { - let _t = thread::scoped(move|| { + thread::spawn(move|| { let mut samples_chan = samples_chan; // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. @@ -34,7 +34,7 @@ fn foo(name: String, samples_chan: Sender) { }); samples_chan.send(Msg::GetSamples(name.clone(), callback)); - }); + }).join(); } pub fn main() {} diff --git a/src/test/run-pass/issue-9396.rs b/src/test/run-pass/issue-9396.rs index bfaf060e43c..6845d3b3aec 100644 --- a/src/test/run-pass/issue-9396.rs +++ b/src/test/run-pass/issue-9396.rs @@ -19,7 +19,7 @@ use std::time::Duration; pub fn main() { let (tx, rx) = channel(); - let _t = thread::scoped(move||{ + let t = thread::spawn(move||{ let mut timer = Timer::new().unwrap(); timer.sleep(Duration::milliseconds(10)); tx.send(()).unwrap(); @@ -31,4 +31,5 @@ pub fn main() { Err(TryRecvError::Disconnected) => unreachable!() } } + t.join(); } diff --git a/src/test/run-pass/ivec-tag.rs b/src/test/run-pass/ivec-tag.rs index 8ae084dce8c..3f0daf2610c 100644 --- a/src/test/run-pass/ivec-tag.rs +++ b/src/test/run-pass/ivec-tag.rs @@ -23,9 +23,10 @@ fn producer(tx: &Sender>) { pub fn main() { let (tx, rx) = channel::>(); - let _prod = thread::scoped(move|| { + let prod = thread::spawn(move|| { producer(&tx) }); let _data: Vec = rx.recv().unwrap(); + prod.join(); } diff --git a/src/test/run-pass/kindck-implicit-close-over-mut-var.rs b/src/test/run-pass/kindck-implicit-close-over-mut-var.rs index 11b1d70137d..a81c0846a27 100644 --- a/src/test/run-pass/kindck-implicit-close-over-mut-var.rs +++ b/src/test/run-pass/kindck-implicit-close-over-mut-var.rs @@ -18,12 +18,13 @@ fn foo() { // Here, i is *copied* into the proc (heap closure). // Requires allocation. The proc's copy is not mutable. let mut i = 0; - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { user(i); println!("spawned {}", i) }); i += 1; - println!("original {}", i) + println!("original {}", i); + t.join(); } fn bar() { @@ -31,10 +32,11 @@ fn bar() { // mutable outside of the proc. let mut i = 0; while i < 10 { - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { user(i); }); i += 1; + t.join(); } } @@ -42,12 +44,13 @@ fn car() { // Here, i must be shadowed in the proc to be mutable. let mut i = 0; while i < 10 { - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { let mut i = i; i += 1; user(i); }); i += 1; + t.join(); } } diff --git a/src/test/run-pass/moves-based-on-type-capture-clause.rs b/src/test/run-pass/moves-based-on-type-capture-clause.rs index b6509d28036..c7ef9776367 100644 --- a/src/test/run-pass/moves-based-on-type-capture-clause.rs +++ b/src/test/run-pass/moves-based-on-type-capture-clause.rs @@ -14,7 +14,7 @@ use std::thread; pub fn main() { let x = "Hello world!".to_string(); - let _t = thread::scoped(move|| { + thread::spawn(move|| { println!("{}", x); - }); + }).join(); } diff --git a/src/test/run-pass/out-of-stack-new-thread-no-split.rs b/src/test/run-pass/out-of-stack-new-thread-no-split.rs index f08ed6e7f9c..6e4901b82d7 100644 --- a/src/test/run-pass/out-of-stack-new-thread-no-split.rs +++ b/src/test/run-pass/out-of-stack-new-thread-no-split.rs @@ -37,7 +37,7 @@ fn recurse() { fn main() { let args: Vec = env::args().collect(); if args.len() > 1 && args[1] == "recurse" { - let _t = thread::scoped(recurse); + thread::spawn(recurse).join(); } else { let recurse = Command::new(&args[0]).arg("recurse").output().unwrap(); assert!(!recurse.status.success()); diff --git a/src/test/run-pass/rust-log-filter.rs b/src/test/run-pass/rust-log-filter.rs index 660b1e2036d..c65d8dd3d13 100644 --- a/src/test/run-pass/rust-log-filter.rs +++ b/src/test/run-pass/rust-log-filter.rs @@ -41,7 +41,7 @@ impl log::Logger for ChannelLogger { pub fn main() { let (logger, rx) = ChannelLogger::new(); - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { log::set_logger(logger); info!("foo"); @@ -54,4 +54,6 @@ pub fn main() { assert_eq!(rx.recv().unwrap(), "foo bar"); assert_eq!(rx.recv().unwrap(), "bar foo"); assert!(rx.recv().is_err()); + + t.join(); } diff --git a/src/test/run-pass/send-is-not-static-par-for.rs b/src/test/run-pass/send-is-not-static-par-for.rs index 99ae3b7c7d8..5f0902d34d3 100644 --- a/src/test/run-pass/send-is-not-static-par-for.rs +++ b/src/test/run-pass/send-is-not-static-par-for.rs @@ -10,7 +10,7 @@ // pretty-expanded FIXME #23616 -#![feature(core, std_misc)] +#![feature(core, std_misc, scoped)] use std::thread; use std::sync::Mutex; @@ -25,7 +25,6 @@ fn par_for(iter: I, f: F) f(elem) }) }).collect(); - } fn sum(x: &[i32]) { diff --git a/src/test/run-pass/send-resource.rs b/src/test/run-pass/send-resource.rs index 3f64b2adb63..66878d98c84 100644 --- a/src/test/run-pass/send-resource.rs +++ b/src/test/run-pass/send-resource.rs @@ -32,7 +32,7 @@ fn test(f: isize) -> test { pub fn main() { let (tx, rx) = channel(); - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { let (tx2, rx2) = channel(); tx.send(tx2).unwrap(); @@ -40,4 +40,6 @@ pub fn main() { }); rx.recv().unwrap().send(test(42)).unwrap(); + + t.join(); } diff --git a/src/test/run-pass/spawn-fn.rs b/src/test/run-pass/spawn-fn.rs index efddf0455cd..4a35ed609e0 100644 --- a/src/test/run-pass/spawn-fn.rs +++ b/src/test/run-pass/spawn-fn.rs @@ -16,13 +16,16 @@ fn x(s: String, n: isize) { } pub fn main() { - let _t = thread::scoped(|| x("hello from first spawned fn".to_string(), 65) ); - let _t = thread::scoped(|| x("hello from second spawned fn".to_string(), 66) ); - let _t = thread::scoped(|| x("hello from third spawned fn".to_string(), 67) ); + let t1 = thread::spawn(|| x("hello from first spawned fn".to_string(), 65) ); + let t2 = thread::spawn(|| x("hello from second spawned fn".to_string(), 66) ); + let t3 = thread::spawn(|| x("hello from third spawned fn".to_string(), 67) ); let mut i = 30; while i > 0 { i = i - 1; println!("parent sleeping"); thread::yield_now(); } + t1.join(); + t2.join(); + t3.join(); } diff --git a/src/test/run-pass/task-comm-0.rs b/src/test/run-pass/task-comm-0.rs index 786dd2c7612..1409caf9c70 100644 --- a/src/test/run-pass/task-comm-0.rs +++ b/src/test/run-pass/task-comm-0.rs @@ -26,7 +26,7 @@ fn test05_start(tx : &Sender) { fn test05() { let (tx, rx) = channel(); - let _t = thread::scoped(move|| { test05_start(&tx) }); + let t = thread::spawn(move|| { test05_start(&tx) }); let mut value: isize = rx.recv().unwrap(); println!("{}", value); value = rx.recv().unwrap(); @@ -34,4 +34,5 @@ fn test05() { value = rx.recv().unwrap(); println!("{}", value); assert_eq!(value, 30); + t.join(); } diff --git a/src/test/run-pass/task-comm-1.rs b/src/test/run-pass/task-comm-1.rs index 9c3466f162b..b3327d82c3e 100644 --- a/src/test/run-pass/task-comm-1.rs +++ b/src/test/run-pass/task-comm-1.rs @@ -17,6 +17,6 @@ pub fn main() { test00(); } fn start() { println!("Started / Finished task."); } fn test00() { - let _ = thread::scoped(move|| start() ).join(); + thread::spawn(move|| start() ).join(); println!("Completing."); } diff --git a/src/test/run-pass/task-comm-10.rs b/src/test/run-pass/task-comm-10.rs index f25bb3ff71a..a796750ef88 100644 --- a/src/test/run-pass/task-comm-10.rs +++ b/src/test/run-pass/task-comm-10.rs @@ -29,10 +29,12 @@ fn start(tx: &Sender>) { pub fn main() { let (tx, rx) = channel(); - let _child = thread::scoped(move|| { start(&tx) }); + let child = thread::spawn(move|| { start(&tx) }); let mut c = rx.recv().unwrap(); c.send("A".to_string()).unwrap(); c.send("B".to_string()).unwrap(); thread::yield_now(); + + child.join(); } diff --git a/src/test/run-pass/task-comm-11.rs b/src/test/run-pass/task-comm-11.rs index ec9ed53c1dc..7af8f5d3b35 100644 --- a/src/test/run-pass/task-comm-11.rs +++ b/src/test/run-pass/task-comm-11.rs @@ -22,8 +22,9 @@ fn start(tx: &Sender>) { pub fn main() { let (tx, rx) = channel(); - let _child = thread::scoped(move|| { + let child = thread::spawn(move|| { start(&tx) }); let _tx = rx.recv().unwrap(); + child.join(); } diff --git a/src/test/run-pass/task-comm-12.rs b/src/test/run-pass/task-comm-12.rs index 03305091a2d..f8d608d3168 100644 --- a/src/test/run-pass/task-comm-12.rs +++ b/src/test/run-pass/task-comm-12.rs @@ -18,7 +18,7 @@ fn start(_task_number: isize) { println!("Started / Finished task."); } fn test00() { let i: isize = 0; - let mut result = thread::scoped(move|| { + let mut result = thread::spawn(move|| { start(i) }); diff --git a/src/test/run-pass/task-comm-13.rs b/src/test/run-pass/task-comm-13.rs index 15ceacd672f..156ddd9c77f 100644 --- a/src/test/run-pass/task-comm-13.rs +++ b/src/test/run-pass/task-comm-13.rs @@ -21,6 +21,6 @@ fn start(tx: &Sender, start: isize, number_of_messages: isize) { pub fn main() { println!("Check that we don't deadlock."); let (tx, rx) = channel(); - let _t = thread::scoped(move|| { start(&tx, 0, 10) }).join(); + let _ = thread::spawn(move|| { start(&tx, 0, 10) }).join(); println!("Joined task"); } diff --git a/src/test/run-pass/task-comm-14.rs b/src/test/run-pass/task-comm-14.rs index 1e2d9fe52df..0048d7d2d73 100644 --- a/src/test/run-pass/task-comm-14.rs +++ b/src/test/run-pass/task-comm-14.rs @@ -21,7 +21,7 @@ pub fn main() { while (i > 0) { println!("{}", i); let tx = tx.clone(); - thread::scoped({let i = i; move|| { child(i, &tx) }}); + thread::spawn({let i = i; move|| { child(i, &tx) }}); i = i - 1; } diff --git a/src/test/run-pass/task-comm-15.rs b/src/test/run-pass/task-comm-15.rs index 2663595aecf..1d853b3e67f 100644 --- a/src/test/run-pass/task-comm-15.rs +++ b/src/test/run-pass/task-comm-15.rs @@ -29,8 +29,9 @@ pub fn main() { // the child's point of view the receiver may die. We should // drop messages on the floor in this case, and not crash! let (tx, rx) = channel(); - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { start(&tx, 10) }); rx.recv(); + t.join(); } diff --git a/src/test/run-pass/task-comm-17.rs b/src/test/run-pass/task-comm-17.rs index de334c77aa3..8f6f971ce35 100644 --- a/src/test/run-pass/task-comm-17.rs +++ b/src/test/run-pass/task-comm-17.rs @@ -22,5 +22,5 @@ fn f() { } pub fn main() { - let _t = thread::scoped(move|| f() ).join(); + thread::spawn(move|| f() ).join(); } diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index 254ad653c48..25f40757b7b 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -42,7 +42,7 @@ fn test00() { let mut results = Vec::new(); while i < number_of_tasks { let tx = tx.clone(); - results.push(thread::scoped({ + results.push(thread::spawn({ let i = i; move|| { test00_start(&tx, i, number_of_messages) diff --git a/src/test/run-pass/task-comm-7.rs b/src/test/run-pass/task-comm-7.rs index b05e36552a2..aa73925874f 100644 --- a/src/test/run-pass/task-comm-7.rs +++ b/src/test/run-pass/task-comm-7.rs @@ -31,19 +31,19 @@ fn test00() { let number_of_messages: isize = 10; let tx2 = tx.clone(); - let _t = thread::scoped(move|| { + let t1 = thread::spawn(move|| { test00_start(&tx2, number_of_messages * 0, number_of_messages); }); let tx2 = tx.clone(); - let _t = thread::scoped(move|| { + let t2 = thread::spawn(move|| { test00_start(&tx2, number_of_messages * 1, number_of_messages); }); let tx2 = tx.clone(); - let _t = thread::scoped(move|| { + let t3 = thread::spawn(move|| { test00_start(&tx2, number_of_messages * 2, number_of_messages); }); let tx2 = tx.clone(); - let _t = thread::scoped(move|| { + let t4 = thread::spawn(move|| { test00_start(&tx2, number_of_messages * 3, number_of_messages); }); @@ -61,4 +61,9 @@ fn test00() { } assert_eq!(sum, number_of_messages * 4 * (number_of_messages * 4 - 1) / 2); + + t1.join(); + t2.join(); + t3.join(); + t4.join(); } diff --git a/src/test/run-pass/task-comm-9.rs b/src/test/run-pass/task-comm-9.rs index 758764aa9fd..d8eec4169e3 100644 --- a/src/test/run-pass/task-comm-9.rs +++ b/src/test/run-pass/task-comm-9.rs @@ -26,7 +26,7 @@ fn test00() { let (tx, rx) = channel(); let number_of_messages: isize = 10; - let result = thread::scoped(move|| { + let result = thread::spawn(move|| { test00_start(&tx, number_of_messages); }); diff --git a/src/test/run-pass/task-life-0.rs b/src/test/run-pass/task-life-0.rs index b97f4355b3e..ba8819fd0b0 100644 --- a/src/test/run-pass/task-life-0.rs +++ b/src/test/run-pass/task-life-0.rs @@ -15,7 +15,7 @@ use std::thread; pub fn main() { - let _t = thread::scoped(move|| child("Hello".to_string()) ); + thread::spawn(move|| child("Hello".to_string()) ).join(); } fn child(_s: String) { diff --git a/src/test/run-pass/task-spawn-move-and-copy.rs b/src/test/run-pass/task-spawn-move-and-copy.rs index aa7b61bf112..548f876421b 100644 --- a/src/test/run-pass/task-spawn-move-and-copy.rs +++ b/src/test/run-pass/task-spawn-move-and-copy.rs @@ -22,11 +22,13 @@ pub fn main() { let x: Box = box 1; let x_in_parent = &(*x) as *const isize as usize; - let _t = thread::scoped(move || { + let t = thread::spawn(move || { let x_in_child = &(*x) as *const isize as usize; tx.send(x_in_child).unwrap(); }); let x_in_child = rx.recv().unwrap(); assert_eq!(x_in_parent, x_in_child); + + t.join(); } diff --git a/src/test/run-pass/tcp-accept-stress.rs b/src/test/run-pass/tcp-accept-stress.rs index 00467e56334..3347287748e 100644 --- a/src/test/run-pass/tcp-accept-stress.rs +++ b/src/test/run-pass/tcp-accept-stress.rs @@ -36,11 +36,11 @@ fn test() { let (srv_tx, srv_rx) = channel(); let (cli_tx, cli_rx) = channel(); - let _t = (0..N).map(|_| { + let ts1 = (0..N).map(|_| { let a = a.clone(); let cnt = cnt.clone(); let srv_tx = srv_tx.clone(); - thread::scoped(move|| { + thread::spawn(move|| { let mut a = a; loop { match a.accept() { @@ -57,7 +57,7 @@ fn test() { }) }).collect::>(); - let _t = (0..N).map(|_| { + let ts2 = (0..N).map(|_| { let cli_tx = cli_tx.clone(); thread::scoped(move|| { for _ in 0..M { @@ -85,4 +85,7 @@ fn test() { // Everything should have been accepted. assert_eq!(cnt.load(Ordering::SeqCst), N * M); + + for t in ts1 { t.join() } + for t in ts2 { t.join() } } diff --git a/src/test/run-pass/tcp-connect-timeouts.rs b/src/test/run-pass/tcp-connect-timeouts.rs index 64f07a60b35..c31400a832c 100644 --- a/src/test/run-pass/tcp-connect-timeouts.rs +++ b/src/test/run-pass/tcp-connect-timeouts.rs @@ -34,7 +34,7 @@ fn eventual_timeout() { let (tx1, rx1) = channel(); let (_tx2, rx2) = channel::<()>(); - let _t = thread::scoped(move|| { + let t = thread::spawn(move|| { let _l = TcpListener::bind(addr).unwrap().listen(); tx1.send(()).unwrap(); let _ = rx2.recv(); @@ -50,6 +50,7 @@ fn eventual_timeout() { } } panic!("never timed out!"); + t.join(); } fn timeout_success() { diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index 49fac24d0b3..3f99c338c0e 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -64,7 +64,7 @@ fn test_rm_tempdir() { TempDir::new("test_rm_tempdir").unwrap() }; // FIXME(#16640) `: TempDir` annotation shouldn't be necessary - let tmp: TempDir = thread::scoped(f).join(); + let tmp: TempDir = thread::spawn(f).join().unwrap(); path = tmp.path().clone(); assert!(path.exists()); } @@ -108,7 +108,7 @@ fn test_rm_tempdir_close() { TempDir::new("test_rm_tempdir").unwrap() }; // FIXME(#16640) `: TempDir` annotation shouldn't be necessary - let tmp: TempDir = thread::scoped(f).join(); + let tmp: TempDir = thread::spawn(f).join().unwrap(); path = tmp.path().clone(); assert!(path.exists()); tmp.close(); diff --git a/src/test/run-pass/threads.rs b/src/test/run-pass/threads.rs index 969a42a6f87..184338c3294 100644 --- a/src/test/run-pass/threads.rs +++ b/src/test/run-pass/threads.rs @@ -15,7 +15,7 @@ use std::thread; pub fn main() { let mut i = 10; while i > 0 { - thread::scoped({let i = i; move|| child(i)}); + thread::spawn({let i = i; move|| child(i)}).join(); i = i - 1; } println!("main thread exiting"); diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index 02ea7037056..21205a2d7fa 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -83,16 +83,19 @@ pub fn main() { box dogge2 as Box)); let (tx1, rx1) = channel(); let arc1 = arc.clone(); - let _t1 = thread::scoped(move|| { check_legs(arc1); tx1.send(()); }); + let t1 = thread::spawn(move|| { check_legs(arc1); tx1.send(()); }); let (tx2, rx2) = channel(); let arc2 = arc.clone(); - let _t2 = thread::scoped(move|| { check_names(arc2); tx2.send(()); }); + let t2 = thread::spawn(move|| { check_names(arc2); tx2.send(()); }); let (tx3, rx3) = channel(); let arc3 = arc.clone(); - let _t3 = thread::scoped(move|| { check_pedigree(arc3); tx3.send(()); }); + let t3 = thread::spawn(move|| { check_pedigree(arc3); tx3.send(()); }); rx1.recv(); rx2.recv(); rx3.recv(); + t1.join(); + t2.join(); + t3.join(); } fn check_legs(arc: Arc>>) { diff --git a/src/test/run-pass/unique-send-2.rs b/src/test/run-pass/unique-send-2.rs index d80d0e82f4f..c32483f629e 100644 --- a/src/test/run-pass/unique-send-2.rs +++ b/src/test/run-pass/unique-send-2.rs @@ -23,10 +23,10 @@ pub fn main() { let (tx, rx) = channel(); let n = 100; let mut expected = 0; - let _t = (0..n).map(|i| { + let ts = (0..n).map(|i| { expected += i; let tx = tx.clone(); - thread::scoped(move|| { + thread::spawn(move|| { child(&tx, i) }) }).collect::>(); @@ -38,4 +38,6 @@ pub fn main() { } assert_eq!(expected, actual); + + for t in ts { t.join(); } } -- cgit 1.4.1-3-g733a5 From 700e627cf727873a472b1876238aac10b932258b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 10 Apr 2015 11:39:53 -0700 Subject: test: Fixup many library unit tests --- src/libcollections/linked_list.rs | 4 +- src/libcollectionstest/bench.rs | 10 +- src/libcollectionstest/bit/vec.rs | 7 +- src/libcollectionstest/btree/map.rs | 4 +- src/libcollectionstest/slice.rs | 18 +- src/libcoretest/fmt/num.rs | 28 +-- src/libflate/lib.rs | 5 +- src/librand/lib.rs | 16 +- src/librand/rand_impls.rs | 52 ----- src/librustc_back/fs.rs | 2 +- src/libserialize/json.rs | 4 +- src/libserialize/lib.rs | 2 +- src/libstd/collections/hash/map.rs | 4 +- src/libstd/fs.rs | 5 +- src/libstd/lib.rs | 2 +- src/libstd/num/strconv.rs | 28 +-- src/libstd/process.rs | 39 ---- src/libstd/rand/mod.rs | 258 --------------------- src/libstd/rand/reader.rs | 17 +- src/libstd/thread/mod.rs | 5 +- src/libtest/stats.rs | 6 +- .../compile-fail/derive-no-std-not-supported.rs | 6 - src/test/run-make/save-analysis/SubDir/mod.rs | 7 +- src/test/run-make/save-analysis/foo.rs | 51 ++-- src/test/run-make/unicode-input/multiple_files.rs | 2 +- src/test/run-make/unicode-input/span_length.rs | 2 +- 26 files changed, 105 insertions(+), 479 deletions(-) (limited to 'src/libstd/thread') diff --git a/src/libcollections/linked_list.rs b/src/libcollections/linked_list.rs index dbdb7956573..391439bcdf2 100644 --- a/src/libcollections/linked_list.rs +++ b/src/libcollections/linked_list.rs @@ -943,7 +943,7 @@ mod test { use std::clone::Clone; use std::iter::Iterator; use std::option::Option::{Some, None, self}; - use std::rand; + use std::__rand::{thread_rng, Rng}; use std::thread; use std::vec::Vec; @@ -1095,7 +1095,7 @@ mod test { let mut v = vec![]; for i in 0..sz { check_links(&m); - let r: u8 = rand::random(); + let r: u8 = thread_rng().next_u32() as u8; match r % 6 { 0 => { m.pop_back(); diff --git a/src/libcollectionstest/bench.rs b/src/libcollectionstest/bench.rs index 8f2e71b666c..07f8dab0c49 100644 --- a/src/libcollectionstest/bench.rs +++ b/src/libcollectionstest/bench.rs @@ -12,14 +12,13 @@ macro_rules! map_insert_rand_bench { ($name: ident, $n: expr, $map: ident) => ( #[bench] pub fn $name(b: &mut ::test::Bencher) { - use std::rand; - use std::rand::Rng; + use std::__rand::{thread_rng, Rng}; use test::black_box; let n: usize = $n; let mut map = $map::new(); // setup - let mut rng = rand::weak_rng(); + let mut rng = thread_rng(); for _ in 0..n { let i = rng.gen::() % n; @@ -67,8 +66,7 @@ macro_rules! map_find_rand_bench { #[bench] pub fn $name(b: &mut ::test::Bencher) { use std::iter::Iterator; - use std::rand::Rng; - use std::rand; + use std::__rand::{thread_rng, Rng}; use std::vec::Vec; use test::black_box; @@ -76,7 +74,7 @@ macro_rules! map_find_rand_bench { let n: usize = $n; // setup - let mut rng = rand::weak_rng(); + let mut rng = rand::thread_rng(); let mut keys: Vec<_> = (0..n).map(|_| rng.gen::() % n).collect(); for &k in &keys { diff --git a/src/libcollectionstest/bit/vec.rs b/src/libcollectionstest/bit/vec.rs index de3c0586ab7..a6ce9692e70 100644 --- a/src/libcollectionstest/bit/vec.rs +++ b/src/libcollectionstest/bit/vec.rs @@ -633,15 +633,14 @@ fn test_bit_vec_extend() { mod bench { use std::collections::BitVec; use std::u32; - use std::rand::{Rng, self}; + use std::__rand::{Rng, thread_rng}; use test::{Bencher, black_box}; const BENCH_BITS : usize = 1 << 14; - fn rng() -> rand::IsaacRng { - let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; - rand::SeedableRng::from_seed(seed) + fn rng() -> ThreadRng { + thread_rng() } #[bench] diff --git a/src/libcollectionstest/btree/map.rs b/src/libcollectionstest/btree/map.rs index 10d69c9f5ec..9b2ec0eacdc 100644 --- a/src/libcollectionstest/btree/map.rs +++ b/src/libcollectionstest/btree/map.rs @@ -251,7 +251,7 @@ fn test_entry(){ mod bench { use std::collections::BTreeMap; - use std::rand::{Rng, weak_rng}; + use std::rand::{Rng, thread_rng}; use test::{Bencher, black_box}; @@ -269,7 +269,7 @@ mod bench { fn bench_iter(b: &mut Bencher, size: i32) { let mut map = BTreeMap::::new(); - let mut rng = weak_rng(); + let mut rng = thread_rng(); for _ in 0..size { map.insert(rng.gen(), rng.gen()); diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs index 5b0aceb76d1..e3022fc77fa 100644 --- a/src/libcollectionstest/slice.rs +++ b/src/libcollectionstest/slice.rs @@ -1296,7 +1296,7 @@ fn test_to_vec() { mod bench { use std::iter::repeat; use std::{mem, ptr}; - use std::rand::{Rng, weak_rng}; + use std::rand::{Rng, thread_rng}; use test::{Bencher, black_box}; @@ -1465,7 +1465,7 @@ mod bench { #[bench] fn random_inserts(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v: Vec<_> = repeat((0, 0)).take(30).collect(); for _ in 0..100 { @@ -1477,7 +1477,7 @@ mod bench { } #[bench] fn random_removes(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v: Vec<_> = repeat((0, 0)).take(130).collect(); for _ in 0..100 { @@ -1489,7 +1489,7 @@ mod bench { #[bench] fn sort_random_small(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v: Vec<_> = rng.gen_iter::().take(5).collect(); v.sort(); @@ -1499,7 +1499,7 @@ mod bench { #[bench] fn sort_random_medium(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v: Vec<_> = rng.gen_iter::().take(100).collect(); v.sort(); @@ -1509,7 +1509,7 @@ mod bench { #[bench] fn sort_random_large(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v: Vec<_> = rng.gen_iter::().take(10000).collect(); v.sort(); @@ -1530,7 +1530,7 @@ mod bench { #[bench] fn sort_big_random_small(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v = rng.gen_iter::().take(5) .collect::>(); @@ -1541,7 +1541,7 @@ mod bench { #[bench] fn sort_big_random_medium(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v = rng.gen_iter::().take(100) .collect::>(); @@ -1552,7 +1552,7 @@ mod bench { #[bench] fn sort_big_random_large(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { let mut v = rng.gen_iter::().take(10000) .collect::>(); diff --git a/src/libcoretest/fmt/num.rs b/src/libcoretest/fmt/num.rs index ba12ff306e9..cab2175f897 100644 --- a/src/libcoretest/fmt/num.rs +++ b/src/libcoretest/fmt/num.rs @@ -169,42 +169,42 @@ fn test_radix_base_too_large() { mod u32 { use test::Bencher; use core::fmt::radix; - use std::rand::{weak_rng, Rng}; + use std::__rand::{thread_rng, Rng}; use std::io::{Write, sink}; #[bench] fn format_bin(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:b}", rng.gen::()) }) } #[bench] fn format_oct(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:o}", rng.gen::()) }) } #[bench] fn format_dec(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{}", rng.gen::()) }) } #[bench] fn format_hex(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:x}", rng.gen::()) }) } #[bench] fn format_show(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:?}", rng.gen::()) }) } #[bench] fn format_base_36(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{}", radix(rng.gen::(), 36)) }) } } @@ -212,42 +212,42 @@ mod u32 { mod i32 { use test::Bencher; use core::fmt::radix; - use std::rand::{weak_rng, Rng}; + use std::__rand::{thread_rng, Rng}; use std::io::{Write, sink}; #[bench] fn format_bin(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:b}", rng.gen::()) }) } #[bench] fn format_oct(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:o}", rng.gen::()) }) } #[bench] fn format_dec(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{}", rng.gen::()) }) } #[bench] fn format_hex(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:x}", rng.gen::()) }) } #[bench] fn format_show(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{:?}", rng.gen::()) }) } #[bench] fn format_base_36(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { write!(&mut sink(), "{}", radix(rng.gen::(), 36)) }) } } diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 63d1fe968fe..1e0e2018050 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -155,12 +155,11 @@ pub fn inflate_bytes_zlib(bytes: &[u8]) -> Result { mod tests { #![allow(deprecated)] use super::{inflate_bytes, deflate_bytes}; - use std::rand; - use std::rand::Rng; + use std::__rand::{thread_rng, Rng}; #[test] fn test_flate_round_trip() { - let mut r = rand::thread_rng(); + let mut r = thread_rng(); let mut words = vec![]; for _ in 0..20 { let range = r.gen_range(1, 10); diff --git a/src/librand/lib.rs b/src/librand/lib.rs index d7299b939f8..d17165735ea 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -516,25 +516,21 @@ pub struct Closed01(pub F); #[cfg(test)] mod test { - use std::rand; + use std::__rand as rand; - pub struct MyRng { inner: R } + pub struct MyRng { inner: Box } impl ::Rng for MyRng { fn next_u32(&mut self) -> u32 { - fn next(t: &mut T) -> u32 { - use std::rand::Rng; - t.next_u32() - } - next(&mut self.inner) + rand::Rng::next_u32(&mut self.inner) } } pub fn rng() -> MyRng { - MyRng { inner: rand::thread_rng() } + MyRng { inner: Box::new(rand::thread_rng()) } } - pub fn weak_rng() -> MyRng { - MyRng { inner: rand::weak_rng() } + pub fn weak_rng() -> MyRng { + MyRng { inner: Box::new(rand::thread_rng()) } } } diff --git a/src/librand/rand_impls.rs b/src/librand/rand_impls.rs index e2a5276cc78..2f37451ecbb 100644 --- a/src/librand/rand_impls.rs +++ b/src/librand/rand_impls.rs @@ -211,55 +211,3 @@ impl Rand for Option { } } } - -#[cfg(test)] -mod tests { - use std::rand::{Rng, thread_rng, Open01, Closed01}; - - struct ConstantRng(u64); - impl Rng for ConstantRng { - fn next_u32(&mut self) -> u32 { - let ConstantRng(v) = *self; - v as u32 - } - fn next_u64(&mut self) -> u64 { - let ConstantRng(v) = *self; - v - } - } - - #[test] - fn floating_point_edge_cases() { - // the test for exact equality is correct here. - assert!(ConstantRng(0xffff_ffff).gen::() != 1.0); - assert!(ConstantRng(0xffff_ffff_ffff_ffff).gen::() != 1.0); - } - - #[test] - fn rand_open() { - // this is unlikely to catch an incorrect implementation that - // generates exactly 0 or 1, but it keeps it sane. - let mut rng = thread_rng(); - for _ in 0..1_000 { - // strict inequalities - let Open01(f) = rng.gen::>(); - assert!(0.0 < f && f < 1.0); - - let Open01(f) = rng.gen::>(); - assert!(0.0 < f && f < 1.0); - } - } - - #[test] - fn rand_closed() { - let mut rng = thread_rng(); - for _ in 0..1_000 { - // strict inequalities - let Closed01(f) = rng.gen::>(); - assert!(0.0 <= f && f <= 1.0); - - let Closed01(f) = rng.gen::>(); - assert!(0.0 <= f && f <= 1.0); - } - } -} diff --git a/src/librustc_back/fs.rs b/src/librustc_back/fs.rs index ec280a602b0..2e4dedd2ad2 100644 --- a/src/librustc_back/fs.rs +++ b/src/librustc_back/fs.rs @@ -68,7 +68,7 @@ pub fn realpath(original: &Path) -> io::Result { mod test { use tempdir::TempDir; use std::fs::{self, File}; - use std::path::{Path, PathBuf}; + use super::realpath; #[test] fn realpath_works() { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 5890bdec8c1..620ea40b48a 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2627,9 +2627,9 @@ mod tests { use super::{Json, from_str, DecodeResult, DecoderError, JsonEvent, Parser, StackElement, Stack, Decoder, Encoder, EncoderError}; use std::{i64, u64, f32, f64}; + use std::io::prelude::*; use std::collections::BTreeMap; use std::string; - use std::old_io::Writer; #[derive(RustcDecodable, Eq, PartialEq, Debug)] struct OptionData { @@ -3464,7 +3464,6 @@ mod tests { #[test] fn test_encode_hashmap_with_numeric_key() { use std::str::from_utf8; - use std::old_io::Writer; use std::collections::HashMap; let mut hm: HashMap = HashMap::new(); hm.insert(1, true); @@ -3480,7 +3479,6 @@ mod tests { #[test] fn test_prettyencode_hashmap_with_numeric_key() { use std::str::from_utf8; - use std::old_io::Writer; use std::collections::HashMap; let mut hm: HashMap = HashMap::new(); hm.insert(1, true); diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 2efa84e6941..dde79b123e6 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -35,7 +35,7 @@ Core encoding and decoding interfaces. #![feature(std_misc)] #![feature(unicode)] #![feature(str_char)] -#![cfg_attr(test, feature(test, old_io))] +#![cfg_attr(test, feature(test))] // test harness access #[cfg(test)] extern crate test; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 54a3a055768..d0d71a128b6 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1631,7 +1631,7 @@ mod test_map { use super::Entry::{Occupied, Vacant}; use iter::{range_inclusive, range_step_inclusive, repeat}; use cell::RefCell; - use rand::{weak_rng, Rng}; + use rand::{thread_rng, Rng}; #[test] fn test_create_capacity_zero() { @@ -2290,7 +2290,7 @@ mod test_map { } let mut m = HashMap::new(); - let mut rng = weak_rng(); + let mut rng = thread_rng(); // Populate the map with some items. for _ in 0..50 { diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 914830d9dcf..d519e1df13b 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -123,7 +123,7 @@ pub struct WalkDir { /// Opening a file for both reading and writing, as well as creating it if it /// doesn't exist: /// -/// ``` +/// ```no_run /// use std::fs::OpenOptions; /// /// let file = OpenOptions::new() @@ -1195,7 +1195,8 @@ mod tests { pub fn tmpdir() -> TempDir { let p = env::temp_dir(); - let ret = p.join(&format!("rust-{}", rand::random::())); + let mut r = rand::thread_rng(); + let ret = p.join(&format!("rust-{}", r.next_u32())); check!(fs::create_dir(&ret)); TempDir(ret) } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index d613fbe4d42..b2bcbaa7b1c 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -288,7 +288,7 @@ mod rand; #[doc(hidden)] #[unstable(feature = "rand")] pub mod __rand { - pub use rand::{thread_rng, Rng}; + pub use rand::{thread_rng, ThreadRng, Rng}; } // Modules that exist purely to document + host impl docs for primitive types diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index ea869ebae10..8ab66f2328f 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -464,7 +464,7 @@ mod bench { mod usize { use super::test::Bencher; - use rand::{weak_rng, Rng}; + use rand::{thread_rng, Rng}; use std::fmt; #[inline] @@ -474,38 +474,38 @@ mod bench { #[bench] fn to_str_bin(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 2); }) } #[bench] fn to_str_oct(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 8); }) } #[bench] fn to_str_dec(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 10); }) } #[bench] fn to_str_hex(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 16); }) } #[bench] fn to_str_base_36(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 36); }) } } mod isize { use super::test::Bencher; - use rand::{weak_rng, Rng}; + use rand::{thread_rng, Rng}; use std::fmt; #[inline] @@ -515,43 +515,43 @@ mod bench { #[bench] fn to_str_bin(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 2); }) } #[bench] fn to_str_oct(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 8); }) } #[bench] fn to_str_dec(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 10); }) } #[bench] fn to_str_hex(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 16); }) } #[bench] fn to_str_base_36(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { to_string(rng.gen::(), 36); }) } } mod f64 { use super::test::Bencher; - use rand::{weak_rng, Rng}; + use rand::{thread_rng, Rng}; use f64; #[bench] fn float_to_string(b: &mut Bencher) { - let mut rng = weak_rng(); + let mut rng = thread_rng(); b.iter(|| { f64::to_string(rng.gen()); }) } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index cac1540d0ec..a92c6318c32 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -534,8 +534,6 @@ mod tests { use io::prelude::*; use io::ErrorKind; - use old_path::{self, GenericPath}; - use old_io::fs::PathExtensions; use rt::running_on_valgrind; use str; use super::{Command, Output, Stdio}; @@ -748,43 +746,6 @@ mod tests { cmd } - #[cfg(not(target_arch = "aarch64"))] - #[test] - fn test_keep_current_working_dir() { - use os; - let prog = pwd_cmd().spawn().unwrap(); - - let output = String::from_utf8(prog.wait_with_output().unwrap().stdout).unwrap(); - let parent_dir = ::env::current_dir().unwrap().to_str().unwrap().to_string(); - let parent_dir = old_path::Path::new(parent_dir); - let child_dir = old_path::Path::new(output.trim()); - - let parent_stat = parent_dir.stat().unwrap(); - let child_stat = child_dir.stat().unwrap(); - - assert_eq!(parent_stat.unstable.device, child_stat.unstable.device); - assert_eq!(parent_stat.unstable.inode, child_stat.unstable.inode); - } - - #[test] - fn test_change_working_directory() { - use os; - // test changing to the parent of os::getcwd() because we know - // the path exists (and os::getcwd() is not expected to be root) - let parent_dir = ::env::current_dir().unwrap().to_str().unwrap().to_string(); - let parent_dir = old_path::Path::new(parent_dir).dir_path(); - let result = pwd_cmd().current_dir(parent_dir.as_str().unwrap()).output().unwrap(); - - let output = String::from_utf8(result.stdout).unwrap(); - let child_dir = old_path::Path::new(output.trim()); - - let parent_stat = parent_dir.stat().unwrap(); - let child_stat = child_dir.stat().unwrap(); - - assert_eq!(parent_stat.unstable.device, child_stat.unstable.device); - assert_eq!(parent_stat.unstable.inode, child_stat.unstable.inode); - } - #[cfg(all(unix, not(target_os="android")))] pub fn env_cmd() -> Command { Command::new("env") diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 9800a252777..ca5a50f289a 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -354,261 +354,3 @@ impl Rng for ThreadRng { self.rng.borrow_mut().fill_bytes(bytes) } } - -#[cfg(test)] -mod test { - use prelude::v1::*; - use super::{Rng, thread_rng, random, SeedableRng, StdRng, sample}; - use iter::{order, repeat}; - - struct ConstRng { i: u64 } - impl Rng for ConstRng { - fn next_u32(&mut self) -> u32 { self.i as u32 } - fn next_u64(&mut self) -> u64 { self.i } - - // no fill_bytes on purpose - } - - #[test] - fn test_fill_bytes_default() { - let mut r = ConstRng { i: 0x11_22_33_44_55_66_77_88 }; - - // check every remainder mod 8, both in small and big vectors. - let lengths = [0, 1, 2, 3, 4, 5, 6, 7, - 80, 81, 82, 83, 84, 85, 86, 87]; - for &n in &lengths { - let mut v = repeat(0).take(n).collect::>(); - r.fill_bytes(&mut v); - - // use this to get nicer error messages. - for (i, &byte) in v.iter().enumerate() { - if byte == 0 { - panic!("byte {} of {} is zero", i, n) - } - } - } - } - - #[test] - fn test_gen_range() { - let mut r = thread_rng(); - for _ in 0..1000 { - let a = r.gen_range(-3, 42); - assert!(a >= -3 && a < 42); - assert_eq!(r.gen_range(0, 1), 0); - assert_eq!(r.gen_range(-12, -11), -12); - } - - for _ in 0..1000 { - let a = r.gen_range(10, 42); - assert!(a >= 10 && a < 42); - assert_eq!(r.gen_range(0, 1), 0); - assert_eq!(r.gen_range(3_000_000, 3_000_001), 3_000_000); - } - - } - - #[test] - #[should_panic] - fn test_gen_range_panic_int() { - let mut r = thread_rng(); - r.gen_range(5, -2); - } - - #[test] - #[should_panic] - fn test_gen_range_panic_uint() { - let mut r = thread_rng(); - r.gen_range(5, 2); - } - - #[test] - fn test_gen_f64() { - let mut r = thread_rng(); - let a = r.gen::(); - let b = r.gen::(); - debug!("{:?}", (a, b)); - } - - #[test] - fn test_gen_weighted_bool() { - let mut r = thread_rng(); - assert_eq!(r.gen_weighted_bool(0), true); - assert_eq!(r.gen_weighted_bool(1), true); - } - - #[test] - fn test_gen_ascii_str() { - let mut r = thread_rng(); - assert_eq!(r.gen_ascii_chars().take(0).count(), 0); - assert_eq!(r.gen_ascii_chars().take(10).count(), 10); - assert_eq!(r.gen_ascii_chars().take(16).count(), 16); - } - - #[test] - fn test_gen_vec() { - let mut r = thread_rng(); - assert_eq!(r.gen_iter::().take(0).count(), 0); - assert_eq!(r.gen_iter::().take(10).count(), 10); - assert_eq!(r.gen_iter::().take(16).count(), 16); - } - - #[test] - fn test_choose() { - let mut r = thread_rng(); - assert_eq!(r.choose(&[1, 1, 1]).cloned(), Some(1)); - - let v: &[isize] = &[]; - assert_eq!(r.choose(v), None); - } - - #[test] - fn test_shuffle() { - let mut r = thread_rng(); - let empty: &mut [isize] = &mut []; - r.shuffle(empty); - let mut one = [1]; - r.shuffle(&mut one); - let b: &[_] = &[1]; - assert_eq!(one, b); - - let mut two = [1, 2]; - r.shuffle(&mut two); - assert!(two == [1, 2] || two == [2, 1]); - - let mut x = [1, 1, 1]; - r.shuffle(&mut x); - let b: &[_] = &[1, 1, 1]; - assert_eq!(x, b); - } - - #[test] - fn test_thread_rng() { - let mut r = thread_rng(); - r.gen::(); - let mut v = [1, 1, 1]; - r.shuffle(&mut v); - let b: &[_] = &[1, 1, 1]; - assert_eq!(v, b); - assert_eq!(r.gen_range(0, 1), 0); - } - - #[test] - fn test_random() { - // not sure how to test this aside from just getting some values - let _n : usize = random(); - let _f : f32 = random(); - let _o : Option> = random(); - let _many : ((), - (usize, - isize, - Option<(u32, (bool,))>), - (u8, i8, u16, i16, u32, i32, u64, i64), - (f32, (f64, (f64,)))) = random(); - } - - #[test] - fn test_sample() { - let min_val = 1; - let max_val = 100; - - let mut r = thread_rng(); - let vals = (min_val..max_val).collect::>(); - let small_sample = sample(&mut r, vals.iter(), 5); - let large_sample = sample(&mut r, vals.iter(), vals.len() + 5); - - assert_eq!(small_sample.len(), 5); - assert_eq!(large_sample.len(), vals.len()); - - assert!(small_sample.iter().all(|e| { - **e >= min_val && **e <= max_val - })); - } - - #[test] - fn test_std_rng_seeded() { - let s = thread_rng().gen_iter::().take(256).collect::>(); - let mut ra: StdRng = SeedableRng::from_seed(&*s); - let mut rb: StdRng = SeedableRng::from_seed(&*s); - assert!(order::equals(ra.gen_ascii_chars().take(100), - rb.gen_ascii_chars().take(100))); - } - - #[test] - fn test_std_rng_reseed() { - let s = thread_rng().gen_iter::().take(256).collect::>(); - let mut r: StdRng = SeedableRng::from_seed(&*s); - let string1 = r.gen_ascii_chars().take(100).collect::(); - - r.reseed(&s); - - let string2 = r.gen_ascii_chars().take(100).collect::(); - assert_eq!(string1, string2); - } -} - -#[cfg(test)] -mod bench { - extern crate test; - use prelude::v1::*; - - use self::test::Bencher; - use super::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng}; - use super::{OsRng, weak_rng}; - use mem::size_of; - - const RAND_BENCH_N: u64 = 100; - - #[bench] - fn rand_xorshift(b: &mut Bencher) { - let mut rng: XorShiftRng = OsRng::new().unwrap().gen(); - b.iter(|| { - for _ in 0..RAND_BENCH_N { - rng.gen::(); - } - }); - b.bytes = size_of::() as u64 * RAND_BENCH_N; - } - - #[bench] - fn rand_isaac(b: &mut Bencher) { - let mut rng: IsaacRng = OsRng::new().unwrap().gen(); - b.iter(|| { - for _ in 0..RAND_BENCH_N { - rng.gen::(); - } - }); - b.bytes = size_of::() as u64 * RAND_BENCH_N; - } - - #[bench] - fn rand_isaac64(b: &mut Bencher) { - let mut rng: Isaac64Rng = OsRng::new().unwrap().gen(); - b.iter(|| { - for _ in 0..RAND_BENCH_N { - rng.gen::(); - } - }); - b.bytes = size_of::() as u64 * RAND_BENCH_N; - } - - #[bench] - fn rand_std(b: &mut Bencher) { - let mut rng = StdRng::new().unwrap(); - b.iter(|| { - for _ in 0..RAND_BENCH_N { - rng.gen::(); - } - }); - b.bytes = size_of::() as u64 * RAND_BENCH_N; - } - - #[bench] - fn rand_shuffle_100(b: &mut Bencher) { - let mut rng = weak_rng(); - let x : &mut[usize] = &mut [1; 100]; - b.iter(|| { - rng.shuffle(x); - }) - } -} diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index 3d0055b43c7..60645707c6a 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -67,17 +67,16 @@ mod test { use prelude::v1::*; use super::ReaderRng; - use old_io::MemReader; use num::Int; use rand::Rng; #[test] fn test_reader_rng_u64() { // transmute from the target to avoid endianness concerns. - let v = vec![0, 0, 0, 0, 0, 0, 0, 1, - 0 , 0, 0, 0, 0, 0, 0, 2, - 0, 0, 0, 0, 0, 0, 0, 3]; - let mut rng = ReaderRng::new(MemReader::new(v)); + let v = &[0, 0, 0, 0, 0, 0, 0, 1, + 0 , 0, 0, 0, 0, 0, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 3][..]; + let mut rng = ReaderRng::new(v); assert_eq!(rng.next_u64(), 1.to_be()); assert_eq!(rng.next_u64(), 2.to_be()); @@ -85,8 +84,8 @@ mod test { } #[test] fn test_reader_rng_u32() { - let v = vec![0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3]; - let mut rng = ReaderRng::new(MemReader::new(v)); + let v = &[0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3][..]; + let mut rng = ReaderRng::new(v); assert_eq!(rng.next_u32(), 1.to_be()); assert_eq!(rng.next_u32(), 2.to_be()); @@ -97,7 +96,7 @@ mod test { let v = [1, 2, 3, 4, 5, 6, 7, 8]; let mut w = [0; 8]; - let mut rng = ReaderRng::new(MemReader::new(v.to_vec())); + let mut rng = ReaderRng::new(&v[..]); rng.fill_bytes(&mut w); assert!(v == w); @@ -106,7 +105,7 @@ mod test { #[test] #[should_panic] fn test_reader_rng_insufficient_bytes() { - let mut rng = ReaderRng::new(MemReader::new(vec!())); + let mut rng = ReaderRng::new(&[][..]); let mut v = [0; 3]; rng.fill_bytes(&mut v); } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 0e5fee27ffe..c47e2389432 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -728,7 +728,6 @@ mod test { use any::Any; use sync::mpsc::{channel, Sender}; use result; - use std::old_io::{ChanReader, ChanWriter}; use super::{Builder}; use thread; use thunk::Thunk; @@ -967,13 +966,11 @@ mod test { #[test] fn test_park_timeout_unpark_called_other_thread() { - use std::old_io; - for _ in 0..10 { let th = thread::current(); let _guard = thread::spawn(move || { - old_io::timer::sleep(Duration::milliseconds(50)); + super::sleep_ms(50); th.unpark(); }); diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 94dee5ccc36..a786d24ed85 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -43,7 +43,6 @@ pub trait Stats { /// Depends on IEEE-754 arithmetic guarantees. See proof of correctness at: /// ["Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates"] /// (http://www.cs.cmu.edu/~quake-papers/robust-arithmetic.ps) - /// *Discrete & Computational Geometry 18*, 3 (Oct 1997), 305-363, Shewchuk J.R. fn sum(&self) -> T; /// Minimum value of the samples. @@ -334,8 +333,9 @@ pub fn winsorize(samples: &mut [T], pct: T) { mod tests { use stats::Stats; use stats::Summary; - use std::old_io::{self, Writer}; use std::f64; + use std::io::prelude::*; + use std::io; macro_rules! assert_approx_eq { ($a:expr, $b:expr) => ({ @@ -350,7 +350,7 @@ mod tests { let summ2 = Summary::new(samples); - let mut w = old_io::stdout(); + let mut w = io::sink(); let w = &mut w; (write!(w, "\n")).unwrap(); diff --git a/src/test/compile-fail/derive-no-std-not-supported.rs b/src/test/compile-fail/derive-no-std-not-supported.rs index d0cb4f23a8c..327e2c9e0f9 100644 --- a/src/test/compile-fail/derive-no-std-not-supported.rs +++ b/src/test/compile-fail/derive-no-std-not-supported.rs @@ -15,12 +15,6 @@ extern crate core; extern crate rand; extern crate serialize as rustc_serialize; -#[derive(Rand)] //~ ERROR this trait cannot be derived -//~^ WARNING `#[derive(Rand)]` is deprecated -struct Foo { - x: u32, -} - #[derive(RustcEncodable)] //~ ERROR this trait cannot be derived struct Bar { x: u32, diff --git a/src/test/run-make/save-analysis/SubDir/mod.rs b/src/test/run-make/save-analysis/SubDir/mod.rs index 23b7d8bbf09..fe84db08da9 100644 --- a/src/test/run-make/save-analysis/SubDir/mod.rs +++ b/src/test/run-make/save-analysis/SubDir/mod.rs @@ -12,21 +12,18 @@ use sub::sub2 as msalias; use sub::sub2; -use std::old_io::stdio::println; static yy: usize = 25; mod sub { pub mod sub2 { - use std::old_io::stdio::println; pub mod sub3 { - use std::old_io::stdio::println; pub fn hello() { - println("hello from module 3"); + println!("hello from module 3"); } } pub fn hello() { - println("hello from a module"); + println!("hello from a module"); } pub struct nested_struct { diff --git a/src/test/run-make/save-analysis/foo.rs b/src/test/run-make/save-analysis/foo.rs index 56da6693939..fe0f32d97d6 100644 --- a/src/test/run-make/save-analysis/foo.rs +++ b/src/test/run-make/save-analysis/foo.rs @@ -10,7 +10,7 @@ #![ crate_name = "test" ] #![allow(unstable)] -#![feature(box_syntax, old_io, rustc_private, core, zero_one)] +#![feature(box_syntax, rustc_private, core, zero_one)] extern crate graphviz; // A simple rust project @@ -19,7 +19,6 @@ extern crate flate as myflate; use std::collections::{HashMap,HashSet}; use std::cell::RefCell; -use std::old_io::stdio::println; use sub::sub2 as msalias; @@ -61,15 +60,13 @@ fn test_tup_struct(x: TupStruct) -> isize { mod sub { pub mod sub2 { - use std::old_io::stdio::println; pub mod sub3 { - use std::old_io::stdio::println; pub fn hello() { - println("hello from module 3"); + println!("hello from module 3"); } } pub fn hello() { - println("hello from a module"); + println!("hello from a module"); } pub struct nested_struct { @@ -106,7 +103,7 @@ trait SomeTrait: SuperTrait { fn Method(&self, x: u32) -> u32; fn prov(&self, x: u32) -> u32 { - println(&x.to_string()); + println!("{}", &x.to_string()); 42 } fn provided_method(&self) -> u32 { @@ -122,7 +119,7 @@ trait SubTrait: SomeTrait { impl SomeTrait for some_fields { fn Method(&self, x: u32) -> u32 { - println(&x.to_string()); + println!("{}", &x.to_string()); self.field1 } } @@ -134,7 +131,7 @@ impl SubTrait for some_fields {} impl some_fields { fn stat(x: u32) -> u32 { - println(&x.to_string()); + println!("{}", &x.to_string()); 42 } fn stat2(x: &some_fields) -> u32 { @@ -194,20 +191,20 @@ enum SomeStructEnum { fn matchSomeEnum(val: SomeEnum) { match val { - SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); } - SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); } - SomeEnum::Strings(_, _, s3) => { println(s3); } + SomeEnum::Ints(int1, int2) => { println!("{}", &(int1+int2).to_string()); } + SomeEnum::Floats(float1, float2) => { println!("{}", &(float2*float1).to_string()); } + SomeEnum::Strings(_, _, s3) => { println!("{}", s3); } SomeEnum::MyTypes(mt1, mt2) => { - println(&(mt1.field1 - mt2.field1).to_string()); + println!("{}", &(mt1.field1 - mt2.field1).to_string()); } } } fn matchSomeStructEnum(se: SomeStructEnum) { match se { - SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()), - SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()), - SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()), + SomeStructEnum::EnumStruct{a:a, ..} => println!("{}", &a.to_string()), + SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println!("{}", &f_2.field1.to_string()), + SomeStructEnum::EnumStruct3{f1, ..} => println!("{}", &f1.field1.to_string()), } } @@ -215,9 +212,9 @@ fn matchSomeStructEnum(se: SomeStructEnum) { fn matchSomeStructEnum2(se: SomeStructEnum) { use SomeStructEnum::*; match se { - EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()), - EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()), - EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println(&f1.field1.to_string()), + EnumStruct{a: ref aaa, ..} => println!("{}", &aaa.to_string()), + EnumStruct2{f1, f2: f2} => println!("{}", &f1.field1.to_string()), + EnumStruct3{f1, f3: SomeEnum::Ints(_, _), f2} => println!("{}", &f1.field1.to_string()), _ => {}, } } @@ -225,22 +222,22 @@ fn matchSomeStructEnum2(se: SomeStructEnum) { fn matchSomeOtherEnum(val: SomeOtherEnum) { use SomeOtherEnum::{SomeConst2, SomeConst3}; match val { - SomeOtherEnum::SomeConst1 => { println("I'm const1."); } - SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); } + SomeOtherEnum::SomeConst1 => { println!("I'm const1."); } + SomeConst2 | SomeConst3 => { println!("I'm const2 or const3."); } } } fn hello((z, a) : (u32, String), ex: X) { SameDir2::hello(43); - println(&yy.to_string()); + println!("{}", &yy.to_string()); let (x, y): (u32, u32) = (5, 3); - println(&x.to_string()); - println(&z.to_string()); + println!("{}", &x.to_string()); + println!("{}", &z.to_string()); let x: u32 = x; - println(&x.to_string()); + println!("{}", &x.to_string()); let x = "hello"; - println(x); + println!("{}", x); let x = 32.0f32; let _ = (x + ((x * x) + 1.0).sqrt()).ln(); @@ -312,7 +309,7 @@ fn main() { // foo let s3: some_fields = some_fields{ field1: 55}; let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55}; let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55}; - println(&s2.field1.to_string()); + println!("{}", &s2.field1.to_string()); let s5: MyType = box some_fields{ field1: 55}; let s = SameDir::SameStruct{name: "Bob".to_string()}; let s = SubDir::SubStruct{name:"Bob".to_string()}; diff --git a/src/test/run-make/unicode-input/multiple_files.rs b/src/test/run-make/unicode-input/multiple_files.rs index aa2ce785771..b1fe938767d 100644 --- a/src/test/run-make/unicode-input/multiple_files.rs +++ b/src/test/run-make/unicode-input/multiple_files.rs @@ -14,7 +14,7 @@ use std::fs::File; use std::io::prelude::*; use std::path::Path; use std::process::Command; -use std::rand::{thread_rng, Rng}; +use std::__rand::{thread_rng, Rng}; use std::{char, env}; // creates unicode_input_multiple_files_{main,chars}.rs, where the diff --git a/src/test/run-make/unicode-input/span_length.rs b/src/test/run-make/unicode-input/span_length.rs index a70a1600765..0c01a84d1bf 100644 --- a/src/test/run-make/unicode-input/span_length.rs +++ b/src/test/run-make/unicode-input/span_length.rs @@ -15,7 +15,7 @@ use std::io::prelude::*; use std::iter::repeat; use std::path::Path; use std::process::Command; -use std::rand::{thread_rng, Rng}; +use std::__rand::{thread_rng, Rng}; use std::{char, env}; // creates a file with `fn main() { }` and checks the -- cgit 1.4.1-3-g733a5