diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 6a77bf64baee5..bfb7ecb477423 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -164,7 +164,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// for _ in 0..10 { /// let five = Arc::clone(&five); /// -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// println!("{:?}", five); /// }); /// } @@ -184,7 +184,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// for _ in 0..10 { /// let val = Arc::clone(&val); /// -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// let v = val.fetch_add(1, Ordering::SeqCst); /// println!("{:?}", v); /// }); diff --git a/src/librustc_driver/profile/mod.rs b/src/librustc_driver/profile/mod.rs index 061077d05a438..f08c60af66adc 100644 --- a/src/librustc_driver/profile/mod.rs +++ b/src/librustc_driver/profile/mod.rs @@ -22,7 +22,7 @@ pub fn begin() { use std::sync::mpsc::{channel}; let (tx, rx) = channel(); if profq_set_chan(tx) { - thread::spawn(move||profile_queries_thread(rx)); + let _handle = thread::spawn(move || profile_queries_thread(rx)); } } diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index c0561ff0c1731..7f8cfae025683 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -1875,7 +1875,7 @@ const LLVM_WORK_PACKAGE_KIND: time_graph::WorkPackageKind = fn spawn_work(cgcx: CodegenContext, work: WorkItem) { let depth = time_depth(); - thread::spawn(move || { + let _handle = thread::spawn(move || { set_time_depth(depth); // Set up a destructor which will fire off a message that we're done as diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index a18c811d19634..8aaf2b2d2368a 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -234,8 +234,8 @@ macro_rules! eprintln { /// let (tx1, rx1) = mpsc::channel(); /// let (tx2, rx2) = mpsc::channel(); /// -/// thread::spawn(move|| { long_running_thread(); tx1.send(()).unwrap(); }); -/// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); }); +/// let _t = thread::spawn(move || { long_running_thread(); tx1.send(()).unwrap(); }); +/// let _t = thread::spawn(move || { tx2.send(calculate_the_answer()).unwrap(); }); /// /// select! { /// _ = rx1.recv() => println!("the long running thread finished first"), diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index 273c7c1c54a2a..f7d11033dcd3a 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -206,7 +206,7 @@ mod tests { for _ in 0..N - 1 { let c = barrier.clone(); let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(c.wait().is_leader()).unwrap(); }); } diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 3014283da5b27..68d6effe6964b 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -45,7 +45,7 @@ impl WaitTimeoutResult { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// /// // Let's wait 20 milliseconds before notifying the condvar. @@ -103,7 +103,7 @@ impl WaitTimeoutResult { /// let pair2 = pair.clone(); /// /// // Inside of our lock, spawn a new thread, and then wait for it to start. -/// thread::spawn(move|| { +/// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -189,7 +189,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -254,7 +254,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -310,7 +310,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -383,7 +383,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -458,7 +458,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -517,7 +517,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -557,7 +557,7 @@ impl Condvar { /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// - /// thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -663,7 +663,7 @@ mod tests { for _ in 0..N { let data = data.clone(); let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { let &(ref lock, ref cond) = &*data; let mut cnt = lock.lock().unwrap(); *cnt += 1; @@ -697,7 +697,7 @@ mod tests { let pair2 = pair.clone(); // Inside of our lock, spawn a new thread, and then wait for it to start. - thread::spawn(move|| { + let _t = thread::spawn(move|| { let &(ref lock, ref cvar) = &*pair2; let mut started = lock.lock().unwrap(); *started = true; diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 2dd3aebe6108e..11ead59460a32 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -68,7 +68,7 @@ //! //! // Create a simple streaming channel //! let (tx, rx) = channel(); -//! thread::spawn(move|| { +//! let _t = thread::spawn(move|| { //! tx.send(10).unwrap(); //! }); //! assert_eq!(rx.recv().unwrap(), 10); @@ -86,7 +86,7 @@ //! let (tx, rx) = channel(); //! for i in 0..10 { //! let tx = tx.clone(); -//! thread::spawn(move|| { +//! let _t = thread::spawn(move|| { //! tx.send(i).unwrap(); //! }); //! } @@ -116,7 +116,7 @@ //! use std::sync::mpsc::sync_channel; //! //! let (tx, rx) = sync_channel::(0); -//! thread::spawn(move|| { +//! let _t = thread::spawn(move|| { //! // This will wait for the parent thread to start receiving //! tx.send(53).unwrap(); //! }); @@ -317,7 +317,7 @@ mod cache_aligned; /// /// let (send, recv) = channel(); /// -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// send.send("Hello world!").unwrap(); /// thread::sleep(Duration::from_secs(2)); // block for two seconds /// send.send("Delayed for 2 seconds").unwrap(); @@ -359,7 +359,7 @@ impl !Sync for Receiver { } /// /// let (send, recv) = channel(); /// -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// send.send(1u8).unwrap(); /// send.send(2u8).unwrap(); /// send.send(3u8).unwrap(); @@ -401,7 +401,7 @@ pub struct Iter<'a, T: 'a> { /// assert!(receiver.try_iter().next().is_none()); /// println!("Nothing in the buffer..."); /// -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// sender.send(1).unwrap(); /// sender.send(2).unwrap(); /// sender.send(3).unwrap(); @@ -439,7 +439,7 @@ pub struct TryIter<'a, T: 'a> { /// /// let (send, recv) = channel(); /// -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// send.send(1u8).unwrap(); /// send.send(2u8).unwrap(); /// send.send(3u8).unwrap(); @@ -473,12 +473,12 @@ pub struct IntoIter { /// let sender2 = sender.clone(); /// /// // First thread owns sender -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// sender.send(1).unwrap(); /// }); /// /// // Second thread owns sender2 -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// sender2.send(2).unwrap(); /// }); /// @@ -521,13 +521,13 @@ impl !Sync for Sender { } /// let sync_sender2 = sync_sender.clone(); /// /// // First thread owns sync_sender -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// sync_sender.send(1).unwrap(); /// sync_sender.send(2).unwrap(); /// }); /// /// // Second thread owns sync_sender2 -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// sync_sender2.send(3).unwrap(); /// // thread will now block since the buffer is full /// println!("Thread unblocked!"); @@ -710,7 +710,7 @@ impl UnsafeFlavor for Receiver { /// let (sender, receiver) = channel(); /// /// // Spawn off an expensive computation -/// thread::spawn(move|| { +/// let _t = thread::spawn(move || { /// # fn expensive_computation() {} /// sender.send(expensive_computation()).unwrap(); /// }); @@ -765,7 +765,7 @@ pub fn channel() -> (Sender, Receiver) { /// // this returns immediately /// sender.send(1).unwrap(); /// -/// thread::spawn(move|| { +/// let _t = thread::spawn(move|| { /// // this will block until the previous message has been received /// sender.send(2).unwrap(); /// }); @@ -962,7 +962,7 @@ impl SyncSender { /// // Create a rendezvous sync_channel with buffer size 0 /// let (sync_sender, receiver) = sync_channel(0); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// println!("sending message..."); /// sync_sender.send(1).unwrap(); /// // Thread is now blocked until the message is received @@ -1001,14 +1001,14 @@ impl SyncSender { /// let sync_sender2 = sync_sender.clone(); /// /// // First thread owns sync_sender - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// sync_sender.send(1).unwrap(); /// sync_sender.send(2).unwrap(); /// // Thread blocked /// }); /// /// // Second thread owns sync_sender2 - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// // This will return an error and send /// // no message if the buffer is full /// sync_sender2.try_send(3).is_err(); @@ -1258,7 +1258,7 @@ impl Receiver { /// /// let (send, recv) = mpsc::channel(); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// send.send('a').unwrap(); /// }); /// @@ -1277,7 +1277,7 @@ impl Receiver { /// /// let (send, recv) = mpsc::channel(); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// thread::sleep(Duration::from_millis(800)); /// send.send('a').unwrap(); /// }); @@ -1331,7 +1331,7 @@ impl Receiver { /// /// let (send, recv) = mpsc::channel(); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// send.send('a').unwrap(); /// }); /// @@ -1351,7 +1351,7 @@ impl Receiver { /// /// let (send, recv) = mpsc::channel(); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// thread::sleep(Duration::from_millis(800)); /// send.send('a').unwrap(); /// }); @@ -1427,7 +1427,7 @@ impl Receiver { /// /// let (send, recv) = channel(); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// send.send(1).unwrap(); /// send.send(2).unwrap(); /// send.send(3).unwrap(); @@ -1463,7 +1463,7 @@ impl Receiver { /// // nothing is in the buffer yet /// assert!(receiver.try_iter().next().is_none()); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// thread::sleep(Duration::from_secs(1)); /// sender.send(1).unwrap(); /// sender.send(2).unwrap(); @@ -1949,7 +1949,7 @@ mod tests { for _ in 0..NTHREADS { let tx = tx.clone(); - thread::spawn(move|| { + let _handle = thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -2148,14 +2148,14 @@ mod tests { fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { let res = thread::spawn(move|| { rx.recv().unwrap(); }).join(); assert!(res.is_err()); }); let _t = thread::spawn(move|| { - thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(tx); }); }); @@ -2184,7 +2184,7 @@ mod tests { fn send(tx: Sender>, i: i32) { if i == 10 { return } - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(box i).unwrap(); send(tx, i + 1); }); @@ -2193,7 +2193,7 @@ mod tests { fn recv(rx: Receiver>, i: i32) { if i == 10 { return } - thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(*rx.recv().unwrap() == i); recv(rx, i + 1); }); @@ -2217,7 +2217,7 @@ mod tests { let stress = stress_factor() + 100; let timeout = Duration::from_millis(100); - thread::spawn(move || { + let _t = thread::spawn(move || { for i in 0..stress { if i % 2 == 0 { thread::sleep(timeout * 2); @@ -2259,7 +2259,7 @@ mod tests { for i in 0..stress { let tx = tx.clone(); - thread::spawn(move || { + let _t = thread::spawn(move || { thread::sleep(Duration::from_millis(i as u64 * 10)); tx.send(1usize).unwrap(); }); @@ -2296,7 +2296,7 @@ mod tests { let total = 5; for _ in 0..total { let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(()).unwrap(); }); } @@ -2314,7 +2314,7 @@ mod tests { let total = stress_factor() + 100; for _ in 0..total { let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(()).unwrap(); }); } @@ -2586,7 +2586,7 @@ mod sync_tests { #[test] fn chan_gone_concurrent() { let (tx, rx) = sync_channel::(0); - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); }); @@ -2596,7 +2596,7 @@ mod sync_tests { #[test] fn stress() { let (tx, rx) = sync_channel::(0); - thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..10000 { tx.send(1).unwrap(); } }); for _ in 0..10000 { @@ -2608,7 +2608,7 @@ mod sync_tests { fn stress_recv_timeout_two_threads() { let (tx, rx) = sync_channel::(0); - thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..10000 { tx.send(1).unwrap(); } }); @@ -2634,7 +2634,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (dtx, drx) = sync_channel::<()>(0); - thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut recv_count = 0; loop { match rx.recv_timeout(Duration::from_millis(10)) { @@ -2655,7 +2655,7 @@ mod sync_tests { for _ in 0..NTHREADS { let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -2672,7 +2672,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (dtx, drx) = sync_channel::<()>(0); - thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..AMT * NTHREADS { assert_eq!(rx.recv().unwrap(), 1); } @@ -2685,7 +2685,7 @@ mod sync_tests { for _ in 0..NTHREADS { let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -2856,7 +2856,7 @@ mod sync_tests { assert!(res.is_err()); }); let _t = thread::spawn(move|| { - thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(tx); }); }); @@ -2885,7 +2885,7 @@ mod sync_tests { fn send(tx: SyncSender>, i: i32) { if i == 10 { return } - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(box i).unwrap(); send(tx, i + 1); }); @@ -2894,7 +2894,7 @@ mod sync_tests { fn recv(rx: Receiver>, i: i32) { if i == 10 { return } - thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(*rx.recv().unwrap() == i); recv(rx, i + 1); }); @@ -2916,7 +2916,7 @@ mod sync_tests { let total = stress_factor() + 100; for _ in 0..total { let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(()).unwrap(); }); } diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 296773d20f614..fc621431b489a 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -158,7 +158,7 @@ mod tests { for _ in 0..nthreads { let tx = tx.clone(); let q = q.clone(); - thread::spawn(move|| { + let _handle = thread::spawn(move || { for i in 0..nmsgs { q.push(i); } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 3b4904c98e871..94a4e5e5d8f7c 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -70,7 +70,7 @@ use sys_common::poison::{self, TryLockError, TryLockResult, LockResult}; /// let (tx, rx) = channel(); /// for _ in 0..N { /// let (data, tx) = (data.clone(), tx.clone()); -/// thread::spawn(move || { +/// let _t = thread::spawn(move || { /// // The shared state 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. @@ -519,10 +519,10 @@ mod tests { for _ in 0..K { let tx2 = tx.clone(); let m2 = m.clone(); - thread::spawn(move|| { inc(&m2); tx2.send(()).unwrap(); }); + let _ = thread::spawn(move || { inc(&m2); tx2.send(()).unwrap(); }); let tx2 = tx.clone(); let m2 = m.clone(); - thread::spawn(move|| { inc(&m2); tx2.send(()).unwrap(); }); + let _ = thread::spawn(move || { inc(&m2); tx2.send(()).unwrap(); }); } drop(tx); diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 6fd8b6a5bbae4..2be40fc3f1cfc 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -490,7 +490,7 @@ mod tests { let (tx, rx) = channel(); for _ in 0..10 { let tx = tx.clone(); - thread::spawn(move|| { + let _t = thread::spawn(move || { for _ in 0..4 { thread::yield_now() } unsafe { O.call_once(|| { diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index f7fdedc0d2179..6b3ad07a3bdd3 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -183,7 +183,7 @@ impl RwLock { /// let n = lock.read().unwrap(); /// assert_eq!(*n, 1); /// - /// thread::spawn(move || { + /// let _t = thread::spawn(move || { /// let r = c_lock.read(); /// assert!(r.is_ok()); /// }).join().unwrap(); @@ -594,7 +594,7 @@ mod tests { for _ in 0..N { let tx = tx.clone(); let r = r.clone(); - thread::spawn(move || { + let _t = thread::spawn(move || { let mut rng = rand::thread_rng(); for _ in 0..M { if rng.gen_weighted_bool(N) { @@ -663,7 +663,7 @@ mod tests { let arc2 = arc.clone(); let (tx, rx) = channel(); - thread::spawn(move || { + let _t = thread::spawn(move || { let mut lock = arc2.write().unwrap(); for _ in 0..10 { let tmp = *lock; diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index ad437658d144a..a5d1eb4990303 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -695,7 +695,7 @@ impl IntoRawFd for net::UdpSocket { /// match stream { /// Ok(stream) => { /// /* connection succeeded */ -/// thread::spawn(|| handle_client(stream)); +/// let _t = thread::spawn(|| handle_client(stream)); /// } /// Err(err) => { /// /* connection failed */ @@ -873,7 +873,7 @@ impl UnixListener { /// for stream in listener.incoming() { /// match stream { /// Ok(stream) => { - /// thread::spawn(|| handle_client(stream)); + /// let _t = thread::spawn(|| handle_client(stream)); /// } /// Err(err) => { /// break; @@ -940,7 +940,7 @@ impl<'a> IntoIterator for &'a UnixListener { /// for stream in listener.incoming() { /// match stream { /// Ok(stream) => { -/// thread::spawn(|| handle_client(stream)); +/// let _t = thread::spawn(|| handle_client(stream)); /// } /// Err(err) => { /// break; diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 99479bc56eff3..95994e55fa01f 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -49,7 +49,7 @@ use mem; /// }); /// /// // each thread starts out with the initial value of 1 -/// thread::spawn(move|| { +/// let _t = thread::spawn(move|| { /// FOO.with(|f| { /// assert_eq!(*f.borrow(), 1); /// *f.borrow_mut() = 3; diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 71aee673cfe3e..077a99fb97281 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -36,9 +36,7 @@ //! non-zero exit code. //! //! When the main thread of a Rust program terminates, the entire program shuts -//! down, even if other threads are still running. However, this module provides -//! convenient facilities for automatically waiting for the termination of a -//! child thread (i.e., join). +//! down, even if other threads are still running. //! //! ## Spawning a thread //! @@ -47,7 +45,7 @@ //! ```rust //! use std::thread; //! -//! thread::spawn(move || { +//! let _t = thread::spawn(move || { //! // some work here //! }); //! ``` @@ -1177,7 +1175,7 @@ pub type Result = ::result::Result>; // parent thread never reads this packet until the child has exited). // // This packet itself is then stored into a `JoinInner` which in turns is placed -// in `JoinHandle` and `JoinGuard`. Due to the usage of `UnsafeCell` we need to +// in `JoinHandle`. Due to the usage of `UnsafeCell` we need to // manually worry about impls like Send and Sync. The type `T` should // already always be Send (otherwise the thread could not have been created) and // this type is inherently Sync because no methods take &self. Regardless, @@ -1267,6 +1265,8 @@ impl JoinInner { /// [`Clone`]: ../../std/clone/trait.Clone.html /// [`thread::spawn`]: fn.spawn.html /// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn +#[must_use = "spawned thread must be joined, or else it could be abruptly terminated when the main \ + thread ends"] #[stable(feature = "rust1", since = "1.0.0")] pub struct JoinHandle(JoinInner); @@ -1384,7 +1384,7 @@ mod tests { #[test] fn test_run_basic() { let (tx, rx) = channel(); - thread::spawn(move|| { + let _t = thread::spawn(move || { tx.send(()).unwrap(); }); rx.recv().unwrap(); @@ -1406,14 +1406,13 @@ mod tests { fn f(i: i32, tx: Sender<()>) { let tx = tx.clone(); - thread::spawn(move|| { + let _ = thread::spawn(move|| { if i == 0 { tx.send(()).unwrap(); } else { f(i - 1, tx); } }); - } f(10, tx); rx.recv().unwrap(); @@ -1423,8 +1422,8 @@ mod tests { fn test_spawn_sched_childs_on_default_sched() { let (tx, rx) = channel(); - thread::spawn(move|| { - thread::spawn(move|| { + let _ = thread::spawn(move|| { + let _ = thread::spawn(move|| { tx.send(()).unwrap(); }); }); @@ -1450,14 +1449,14 @@ mod tests { #[test] fn test_avoid_copying_the_body_spawn() { avoid_copying_the_body(|v| { - thread::spawn(move || v()); + let _ = thread::spawn(move || v()); }); } #[test] fn test_avoid_copying_the_body_thread_spawn() { avoid_copying_the_body(|f| { - thread::spawn(move|| { + let _ = thread::spawn(move || { f(); }); }) @@ -1466,7 +1465,7 @@ mod tests { #[test] fn test_avoid_copying_the_body_join() { avoid_copying_the_body(|f| { - let _ = thread::spawn(move|| { + let _ = thread::spawn(move || { f() }).join(); }) @@ -1482,16 +1481,16 @@ mod tests { fn child_no(x: u32) -> Box { return Box::new(move|| { if x < GENERATIONS { - thread::spawn(move|| child_no(x+1)()); + let _ = thread::spawn(move || child_no(x+1)()); } }); } - thread::spawn(|| child_no(0)()); + let _ = thread::spawn(|| child_no(0)()); } #[test] fn test_simple_newsched_spawn() { - thread::spawn(move || {}); + let _ = thread::spawn(move || {}); } #[test] @@ -1570,7 +1569,7 @@ mod tests { for _ in 0..10 { let th = thread::current(); - let _guard = thread::spawn(move || { + let _handle = thread::spawn(move || { super::sleep(Duration::from_millis(50)); th.unpark(); }); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 82077bc4cd482..f66246a28cfd4 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1441,7 +1441,7 @@ pub fn run_test( let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32"); if supports_threads { let cfg = thread::Builder::new().name(name.as_slice().to_owned()); - cfg.spawn(runtest).unwrap(); + let _handle = cfg.spawn(runtest).unwrap(); } else { runtest(); }