From f203079f8917276041304939953fc553ba25c8c2 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 7 Mar 2018 22:59:47 +0100 Subject: [PATCH 1/5] Mark JoinHandle with #[must_use] --- src/libstd/thread/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 71aee673cfe3..4c5921d44b20 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1267,6 +1267,7 @@ impl JoinInner { /// [`Clone`]: ../../std/clone/trait.Clone.html /// [`thread::spawn`]: fn.spawn.html /// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn +#[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub struct JoinHandle(JoinInner); From 07247c449f9f3fa9c190c2952c0a0c5554789649 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 8 Mar 2018 01:55:23 +0100 Subject: [PATCH 2/5] Fix a few warnings --- src/librustc_driver/profile/mod.rs | 2 +- src/libtest/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_driver/profile/mod.rs b/src/librustc_driver/profile/mod.rs index 061077d05a43..933ac301ba75 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/libtest/lib.rs b/src/libtest/lib.rs index 82077bc4cd48..f66246a28cfd 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(); } From 433ad9ae29eb8f18c9c4d7b9a7e7a2f0641eb3df Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 8 Mar 2018 12:53:22 +0100 Subject: [PATCH 3/5] Fix more warnings --- src/librustc_driver/profile/mod.rs | 2 +- src/librustc_trans/back/write.rs | 2 +- src/libstd/sync/barrier.rs | 2 +- src/libstd/sync/condvar.rs | 4 +-- src/libstd/sync/mpsc/mod.rs | 40 +++++++++++++++--------------- src/libstd/sync/mpsc/mpsc_queue.rs | 2 +- src/libstd/sync/mutex.rs | 4 +-- src/libstd/sync/once.rs | 2 +- src/libstd/sync/rwlock.rs | 4 +-- src/libstd/thread/mod.rs | 23 ++++++++--------- 10 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/librustc_driver/profile/mod.rs b/src/librustc_driver/profile/mod.rs index 933ac301ba75..f08c60af66ad 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) { - let _handle = 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 c0561ff0c173..7f8cfae02568 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/sync/barrier.rs b/src/libstd/sync/barrier.rs index 273c7c1c54a2..f7d11033dcd3 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 3014283da5b2..cf7611adc93a 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -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 2dd3aebe6108..0d85f26e576e 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -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 296773d20f61..fc621431b489 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 3b4904c98e87..c26393dc7b74 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -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 6fd8b6a5bbae..2be40fc3f1cf 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 f7fdedc0d217..6cf5370d60af 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -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/thread/mod.rs b/src/libstd/thread/mod.rs index 4c5921d44b20..15e7d64bb09d 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1177,7 +1177,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, @@ -1407,14 +1407,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(); @@ -1424,8 +1423,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(); }); }); @@ -1451,14 +1450,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(); }); }) @@ -1467,7 +1466,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(); }) @@ -1483,16 +1482,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] @@ -1571,7 +1570,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(); }); From a4987dfd275b07af8da93619fc4d3986d4acec6e Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 8 Mar 2018 14:43:05 +0100 Subject: [PATCH 4/5] Fix warnings in doctests --- src/liballoc/arc.rs | 4 ++-- src/libstd/macros.rs | 4 ++-- src/libstd/sync/condvar.rs | 18 +++++++------- src/libstd/sync/mpsc/mod.rs | 44 +++++++++++++++++----------------- src/libstd/sync/mutex.rs | 2 +- src/libstd/sync/rwlock.rs | 2 +- src/libstd/sys/unix/ext/net.rs | 6 ++--- src/libstd/thread/local.rs | 2 +- src/libstd/thread/mod.rs | 4 ++-- 9 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 6a77bf64baee..bfb7ecb47742 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/libstd/macros.rs b/src/libstd/macros.rs index a18c811d1963..8aaf2b2d2368 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/condvar.rs b/src/libstd/sync/condvar.rs index cf7611adc93a..68d6effe6964 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; diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 0d85f26e576e..11ead59460a3 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(); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index c26393dc7b74..94a4e5e5d8f7 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. diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 6cf5370d60af..6b3ad07a3bdd 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(); diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index ad437658d144..a5d1eb499030 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 99479bc56eff..95994e55fa01 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 15e7d64bb09d..f8dda01ef79c 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -47,7 +47,7 @@ //! ```rust //! use std::thread; //! -//! thread::spawn(move || { +//! let _t = thread::spawn(move || { //! // some work here //! }); //! ``` @@ -1385,7 +1385,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(); From a8b58deec4546ef8deab2821e6989429d707f208 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 8 Mar 2018 19:24:00 +0100 Subject: [PATCH 5/5] Add a message to must_use --- src/libstd/thread/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index f8dda01ef79c..077a99fb9728 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 //! @@ -1267,7 +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] +#[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);