]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/sync/mpsc/mod.rs
Deprecate Error::description for real
[rust.git] / src / libstd / sync / mpsc / mod.rs
index c2884a28f3ccdb57ceda20b368f3cfcea59d9c59..0e334c191e7b91feff84e4caec95fecde44dce54 100644 (file)
 // And now that you've seen all the races that I found and attempted to fix,
 // here's the code for you to find some more!
 
-use crate::sync::Arc;
+use crate::cell::UnsafeCell;
 use crate::error;
 use crate::fmt;
 use crate::mem;
-use crate::cell::UnsafeCell;
+use crate::sync::Arc;
 use crate::time::{Duration, Instant};
 
 mod blocking;
+mod mpsc_queue;
 mod oneshot;
 mod shared;
+mod spsc_queue;
 mod stream;
 mod sync;
-mod mpsc_queue;
-mod spsc_queue;
 
 mod cache_aligned;
 
@@ -322,10 +322,10 @@ pub struct Receiver<T> {
 // The receiver port can be sent from place to place, so long as it
 // is not used to receive non-sendable things.
 #[stable(feature = "rust1", since = "1.0.0")]
-unsafe impl<T: Send> Send for Receiver<T> { }
+unsafe impl<T: Send> Send for Receiver<T> {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T> !Sync for Receiver<T> { }
+impl<T> !Sync for Receiver<T> {}
 
 /// An iterator over messages on a [`Receiver`], created by [`iter`].
 ///
@@ -359,7 +359,7 @@ impl<T> !Sync for Receiver<T> { }
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Debug)]
 pub struct Iter<'a, T: 'a> {
-    rx: &'a Receiver<T>
+    rx: &'a Receiver<T>,
 }
 
 /// An iterator that attempts to yield all pending values for a [`Receiver`],
@@ -404,7 +404,7 @@ pub struct Iter<'a, T: 'a> {
 #[stable(feature = "receiver_try_iter", since = "1.15.0")]
 #[derive(Debug)]
 pub struct TryIter<'a, T: 'a> {
-    rx: &'a Receiver<T>
+    rx: &'a Receiver<T>,
 }
 
 /// An owning iterator over messages on a [`Receiver`],
@@ -439,7 +439,7 @@ pub struct TryIter<'a, T: 'a> {
 #[stable(feature = "receiver_into_iter", since = "1.1.0")]
 #[derive(Debug)]
 pub struct IntoIter<T> {
-    rx: Receiver<T>
+    rx: Receiver<T>,
 }
 
 /// The sending-half of Rust's asynchronous [`channel`] type. This half can only be
@@ -482,10 +482,10 @@ pub struct Sender<T> {
 // The send port can be sent from place to place, so long as it
 // is not used to send non-sendable things.
 #[stable(feature = "rust1", since = "1.0.0")]
-unsafe impl<T: Send> Send for Sender<T> { }
+unsafe impl<T: Send> Send for Sender<T> {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T> !Sync for Sender<T> { }
+impl<T> !Sync for Sender<T> {}
 
 /// The sending-half of Rust's synchronous [`sync_channel`] type.
 ///
@@ -772,9 +772,7 @@ pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
 
 impl<T> Sender<T> {
     fn new(inner: Flavor<T>) -> Sender<T> {
-        Sender {
-            inner: UnsafeCell::new(inner),
-        }
+        Sender { inner: UnsafeCell::new(inner) }
     }
 
     /// Attempts to send a value on this channel, returning it back if it could
@@ -856,8 +854,7 @@ fn clone(&self) -> Sender<T> {
                     let guard = a.postinit_lock();
                     let rx = Receiver::new(Flavor::Shared(a.clone()));
                     let sleeper = match p.upgrade(rx) {
-                        oneshot::UpSuccess |
-                        oneshot::UpDisconnected => None,
+                        oneshot::UpSuccess | oneshot::UpDisconnected => None,
                         oneshot::UpWoke(task) => Some(task),
                     };
                     a.inherit_blocker(sleeper, guard);
@@ -870,8 +867,7 @@ fn clone(&self) -> Sender<T> {
                     let guard = a.postinit_lock();
                     let rx = Receiver::new(Flavor::Shared(a.clone()));
                     let sleeper = match p.upgrade(rx) {
-                        stream::UpSuccess |
-                        stream::UpDisconnected => None,
+                        stream::UpSuccess | stream::UpDisconnected => None,
                         stream::UpWoke(task) => Some(task),
                     };
                     a.inherit_blocker(sleeper, guard);
@@ -1078,48 +1074,31 @@ fn new(inner: Flavor<T>) -> Receiver<T> {
     pub fn try_recv(&self) -> Result<T, TryRecvError> {
         loop {
             let new_port = match *unsafe { self.inner() } {
-                Flavor::Oneshot(ref p) => {
-                    match p.try_recv() {
-                        Ok(t) => return Ok(t),
-                        Err(oneshot::Empty) => return Err(TryRecvError::Empty),
-                        Err(oneshot::Disconnected) => {
-                            return Err(TryRecvError::Disconnected)
-                        }
-                        Err(oneshot::Upgraded(rx)) => rx,
-                    }
-                }
-                Flavor::Stream(ref p) => {
-                    match p.try_recv() {
-                        Ok(t) => return Ok(t),
-                        Err(stream::Empty) => return Err(TryRecvError::Empty),
-                        Err(stream::Disconnected) => {
-                            return Err(TryRecvError::Disconnected)
-                        }
-                        Err(stream::Upgraded(rx)) => rx,
-                    }
-                }
-                Flavor::Shared(ref p) => {
-                    match p.try_recv() {
-                        Ok(t) => return Ok(t),
-                        Err(shared::Empty) => return Err(TryRecvError::Empty),
-                        Err(shared::Disconnected) => {
-                            return Err(TryRecvError::Disconnected)
-                        }
-                    }
-                }
-                Flavor::Sync(ref p) => {
-                    match p.try_recv() {
-                        Ok(t) => return Ok(t),
-                        Err(sync::Empty) => return Err(TryRecvError::Empty),
-                        Err(sync::Disconnected) => {
-                            return Err(TryRecvError::Disconnected)
-                        }
-                    }
-                }
+                Flavor::Oneshot(ref p) => match p.try_recv() {
+                    Ok(t) => return Ok(t),
+                    Err(oneshot::Empty) => return Err(TryRecvError::Empty),
+                    Err(oneshot::Disconnected) => return Err(TryRecvError::Disconnected),
+                    Err(oneshot::Upgraded(rx)) => rx,
+                },
+                Flavor::Stream(ref p) => match p.try_recv() {
+                    Ok(t) => return Ok(t),
+                    Err(stream::Empty) => return Err(TryRecvError::Empty),
+                    Err(stream::Disconnected) => return Err(TryRecvError::Disconnected),
+                    Err(stream::Upgraded(rx)) => rx,
+                },
+                Flavor::Shared(ref p) => match p.try_recv() {
+                    Ok(t) => return Ok(t),
+                    Err(shared::Empty) => return Err(TryRecvError::Empty),
+                    Err(shared::Disconnected) => return Err(TryRecvError::Disconnected),
+                },
+                Flavor::Sync(ref p) => match p.try_recv() {
+                    Ok(t) => return Ok(t),
+                    Err(sync::Empty) => return Err(TryRecvError::Empty),
+                    Err(sync::Disconnected) => return Err(TryRecvError::Disconnected),
+                },
             };
             unsafe {
-                mem::swap(self.inner_mut(),
-                          new_port.inner_mut());
+                mem::swap(self.inner_mut(), new_port.inner_mut());
             }
         }
     }
@@ -1185,29 +1164,23 @@ pub fn try_recv(&self) -> Result<T, TryRecvError> {
     pub fn recv(&self) -> Result<T, RecvError> {
         loop {
             let new_port = match *unsafe { self.inner() } {
-                Flavor::Oneshot(ref p) => {
-                    match p.recv(None) {
-                        Ok(t) => return Ok(t),
-                        Err(oneshot::Disconnected) => return Err(RecvError),
-                        Err(oneshot::Upgraded(rx)) => rx,
-                        Err(oneshot::Empty) => unreachable!(),
-                    }
-                }
-                Flavor::Stream(ref p) => {
-                    match p.recv(None) {
-                        Ok(t) => return Ok(t),
-                        Err(stream::Disconnected) => return Err(RecvError),
-                        Err(stream::Upgraded(rx)) => rx,
-                        Err(stream::Empty) => unreachable!(),
-                    }
-                }
-                Flavor::Shared(ref p) => {
-                    match p.recv(None) {
-                        Ok(t) => return Ok(t),
-                        Err(shared::Disconnected) => return Err(RecvError),
-                        Err(shared::Empty) => unreachable!(),
-                    }
-                }
+                Flavor::Oneshot(ref p) => match p.recv(None) {
+                    Ok(t) => return Ok(t),
+                    Err(oneshot::Disconnected) => return Err(RecvError),
+                    Err(oneshot::Upgraded(rx)) => rx,
+                    Err(oneshot::Empty) => unreachable!(),
+                },
+                Flavor::Stream(ref p) => match p.recv(None) {
+                    Ok(t) => return Ok(t),
+                    Err(stream::Disconnected) => return Err(RecvError),
+                    Err(stream::Upgraded(rx)) => rx,
+                    Err(stream::Empty) => unreachable!(),
+                },
+                Flavor::Shared(ref p) => match p.recv(None) {
+                    Ok(t) => return Ok(t),
+                    Err(shared::Disconnected) => return Err(RecvError),
+                    Err(shared::Empty) => unreachable!(),
+                },
                 Flavor::Sync(ref p) => return p.recv(None).map_err(|_| RecvError),
             };
             unsafe {
@@ -1383,36 +1356,28 @@ pub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError> {
 
         loop {
             let port_or_empty = match *unsafe { self.inner() } {
-                Flavor::Oneshot(ref p) => {
-                    match p.recv(Some(deadline)) {
-                        Ok(t) => return Ok(t),
-                        Err(oneshot::Disconnected) => return Err(Disconnected),
-                        Err(oneshot::Upgraded(rx)) => Some(rx),
-                        Err(oneshot::Empty) => None,
-                    }
-                }
-                Flavor::Stream(ref p) => {
-                    match p.recv(Some(deadline)) {
-                        Ok(t) => return Ok(t),
-                        Err(stream::Disconnected) => return Err(Disconnected),
-                        Err(stream::Upgraded(rx)) => Some(rx),
-                        Err(stream::Empty) => None,
-                    }
-                }
-                Flavor::Shared(ref p) => {
-                    match p.recv(Some(deadline)) {
-                        Ok(t) => return Ok(t),
-                        Err(shared::Disconnected) => return Err(Disconnected),
-                        Err(shared::Empty) => None,
-                    }
-                }
-                Flavor::Sync(ref p) => {
-                    match p.recv(Some(deadline)) {
-                        Ok(t) => return Ok(t),
-                        Err(sync::Disconnected) => return Err(Disconnected),
-                        Err(sync::Empty) => None,
-                    }
-                }
+                Flavor::Oneshot(ref p) => match p.recv(Some(deadline)) {
+                    Ok(t) => return Ok(t),
+                    Err(oneshot::Disconnected) => return Err(Disconnected),
+                    Err(oneshot::Upgraded(rx)) => Some(rx),
+                    Err(oneshot::Empty) => None,
+                },
+                Flavor::Stream(ref p) => match p.recv(Some(deadline)) {
+                    Ok(t) => return Ok(t),
+                    Err(stream::Disconnected) => return Err(Disconnected),
+                    Err(stream::Upgraded(rx)) => Some(rx),
+                    Err(stream::Empty) => None,
+                },
+                Flavor::Shared(ref p) => match p.recv(Some(deadline)) {
+                    Ok(t) => return Ok(t),
+                    Err(shared::Disconnected) => return Err(Disconnected),
+                    Err(shared::Empty) => None,
+                },
+                Flavor::Sync(ref p) => match p.recv(Some(deadline)) {
+                    Ok(t) => return Ok(t),
+                    Err(sync::Disconnected) => return Err(Disconnected),
+                    Err(sync::Empty) => None,
+                },
             };
 
             if let Some(new_port) = port_or_empty {
@@ -1502,21 +1467,24 @@ pub fn iter(&self) -> Iter<'_, T> {
     pub fn try_iter(&self) -> TryIter<'_, T> {
         TryIter { rx: self }
     }
-
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T> Iterator for Iter<'a, T> {
     type Item = T;
 
-    fn next(&mut self) -> Option<T> { self.rx.recv().ok() }
+    fn next(&mut self) -> Option<T> {
+        self.rx.recv().ok()
+    }
 }
 
 #[stable(feature = "receiver_try_iter", since = "1.15.0")]
 impl<'a, T> Iterator for TryIter<'a, T> {
     type Item = T;
 
-    fn next(&mut self) -> Option<T> { self.rx.try_recv().ok() }
+    fn next(&mut self) -> Option<T> {
+        self.rx.try_recv().ok()
+    }
 }
 
 #[stable(feature = "receiver_into_iter", since = "1.1.0")]
@@ -1524,17 +1492,21 @@ impl<'a, T> IntoIterator for &'a Receiver<T> {
     type Item = T;
     type IntoIter = Iter<'a, T>;
 
-    fn into_iter(self) -> Iter<'a, T> { self.iter() }
+    fn into_iter(self) -> Iter<'a, T> {
+        self.iter()
+    }
 }
 
 #[stable(feature = "receiver_into_iter", since = "1.1.0")]
 impl<T> Iterator for IntoIter<T> {
     type Item = T;
-    fn next(&mut self) -> Option<T> { self.rx.recv().ok() }
+    fn next(&mut self) -> Option<T> {
+        self.rx.recv().ok()
+    }
 }
 
 #[stable(feature = "receiver_into_iter", since = "1.1.0")]
-impl <T> IntoIterator for Receiver<T> {
+impl<T> IntoIterator for Receiver<T> {
     type Item = T;
     type IntoIter = IntoIter<T>;
 
@@ -1578,6 +1550,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> error::Error for SendError<T> {
+    #[allow(deprecated)]
     fn description(&self) -> &str {
         "sending on a closed channel"
     }
@@ -1597,27 +1570,19 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 impl<T> fmt::Display for TrySendError<T> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            TrySendError::Full(..) => {
-                "sending on a full channel".fmt(f)
-            }
-            TrySendError::Disconnected(..) => {
-                "sending on a closed channel".fmt(f)
-            }
+            TrySendError::Full(..) => "sending on a full channel".fmt(f),
+            TrySendError::Disconnected(..) => "sending on a closed channel".fmt(f),
         }
     }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Send> error::Error for TrySendError<T> {
-
+    #[allow(deprecated)]
     fn description(&self) -> &str {
         match *self {
-            TrySendError::Full(..) => {
-                "sending on a full channel"
-            }
-            TrySendError::Disconnected(..) => {
-                "sending on a closed channel"
-            }
+            TrySendError::Full(..) => "sending on a full channel",
+            TrySendError::Disconnected(..) => "sending on a closed channel",
         }
     }
 }
@@ -1640,7 +1605,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl error::Error for RecvError {
-
+    #[allow(deprecated)]
     fn description(&self) -> &str {
         "receiving on a closed channel"
     }
@@ -1650,27 +1615,19 @@ fn description(&self) -> &str {
 impl fmt::Display for TryRecvError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            TryRecvError::Empty => {
-                "receiving on an empty channel".fmt(f)
-            }
-            TryRecvError::Disconnected => {
-                "receiving on a closed channel".fmt(f)
-            }
+            TryRecvError::Empty => "receiving on an empty channel".fmt(f),
+            TryRecvError::Disconnected => "receiving on a closed channel".fmt(f),
         }
     }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl error::Error for TryRecvError {
-
+    #[allow(deprecated)]
     fn description(&self) -> &str {
         match *self {
-            TryRecvError::Empty => {
-                "receiving on an empty channel"
-            }
-            TryRecvError::Disconnected => {
-                "receiving on a closed channel"
-            }
+            TryRecvError::Empty => "receiving on an empty channel",
+            TryRecvError::Disconnected => "receiving on a closed channel",
         }
     }
 }
@@ -1688,26 +1645,19 @@ fn from(err: RecvError) -> TryRecvError {
 impl fmt::Display for RecvTimeoutError {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match *self {
-            RecvTimeoutError::Timeout => {
-                "timed out waiting on channel".fmt(f)
-            }
-            RecvTimeoutError::Disconnected => {
-                "channel is empty and sending half is closed".fmt(f)
-            }
+            RecvTimeoutError::Timeout => "timed out waiting on channel".fmt(f),
+            RecvTimeoutError::Disconnected => "channel is empty and sending half is closed".fmt(f),
         }
     }
 }
 
 #[stable(feature = "mpsc_recv_timeout_error", since = "1.15.0")]
 impl error::Error for RecvTimeoutError {
+    #[allow(deprecated)]
     fn description(&self) -> &str {
         match *self {
-            RecvTimeoutError::Timeout => {
-                "timed out waiting on channel"
-            }
-            RecvTimeoutError::Disconnected => {
-                "channel is empty and sending half is closed"
-            }
+            RecvTimeoutError::Timeout => "timed out waiting on channel",
+            RecvTimeoutError::Disconnected => "channel is empty and sending half is closed",
         }
     }
 }
@@ -1769,7 +1719,7 @@ fn smoke_shared() {
     #[test]
     fn smoke_threads() {
         let (tx, rx) = channel::<i32>();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             tx.send(1).unwrap();
         });
         assert_eq!(rx.recv().unwrap(), 1);
@@ -1801,7 +1751,7 @@ fn smoke_shared_port_gone2() {
     #[test]
     fn port_gone_concurrent() {
         let (tx, rx) = channel::<i32>();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx.recv().unwrap();
         });
         while tx.send(1).is_ok() {}
@@ -1811,7 +1761,7 @@ fn port_gone_concurrent() {
     fn port_gone_concurrent_shared() {
         let (tx, rx) = channel::<i32>();
         let tx2 = tx.clone();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx.recv().unwrap();
         });
         while tx.send(1).is_ok() && tx2.send(1).is_ok() {}
@@ -1836,7 +1786,7 @@ fn smoke_chan_gone_shared() {
     #[test]
     fn chan_gone_concurrent() {
         let (tx, rx) = channel::<i32>();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             tx.send(1).unwrap();
             tx.send(1).unwrap();
         });
@@ -1846,8 +1796,10 @@ fn chan_gone_concurrent() {
     #[test]
     fn stress() {
         let (tx, rx) = channel::<i32>();
-        let t = thread::spawn(move|| {
-            for _ in 0..10000 { tx.send(1).unwrap(); }
+        let t = thread::spawn(move || {
+            for _ in 0..10000 {
+                tx.send(1).unwrap();
+            }
         });
         for _ in 0..10000 {
             assert_eq!(rx.recv().unwrap(), 1);
@@ -1861,7 +1813,7 @@ fn stress_shared() {
         const NTHREADS: u32 = 8;
         let (tx, rx) = channel::<i32>();
 
-        let t = thread::spawn(move|| {
+        let t = thread::spawn(move || {
             for _ in 0..AMT * NTHREADS {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
@@ -1873,8 +1825,10 @@ fn stress_shared() {
 
         for _ in 0..NTHREADS {
             let tx = tx.clone();
-            thread::spawn(move|| {
-                for _ in 0..AMT { tx.send(1).unwrap(); }
+            thread::spawn(move || {
+                for _ in 0..AMT {
+                    tx.send(1).unwrap();
+                }
             });
         }
         drop(tx);
@@ -1885,14 +1839,14 @@ fn stress_shared() {
     fn send_from_outside_runtime() {
         let (tx1, rx1) = channel::<()>();
         let (tx2, rx2) = channel::<i32>();
-        let t1 = thread::spawn(move|| {
+        let t1 = thread::spawn(move || {
             tx1.send(()).unwrap();
             for _ in 0..40 {
                 assert_eq!(rx2.recv().unwrap(), 1);
             }
         });
         rx1.recv().unwrap();
-        let t2 = thread::spawn(move|| {
+        let t2 = thread::spawn(move || {
             for _ in 0..40 {
                 tx2.send(1).unwrap();
             }
@@ -1904,7 +1858,7 @@ fn send_from_outside_runtime() {
     #[test]
     fn recv_from_outside_runtime() {
         let (tx, rx) = channel::<i32>();
-        let t = thread::spawn(move|| {
+        let t = thread::spawn(move || {
             for _ in 0..40 {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
@@ -1919,11 +1873,11 @@ fn recv_from_outside_runtime() {
     fn no_runtime() {
         let (tx1, rx1) = channel::<i32>();
         let (tx2, rx2) = channel::<i32>();
-        let t1 = thread::spawn(move|| {
+        let t1 = thread::spawn(move || {
             assert_eq!(rx1.recv().unwrap(), 1);
             tx2.send(2).unwrap();
         });
-        let t2 = thread::spawn(move|| {
+        let t2 = thread::spawn(move || {
             tx1.send(1).unwrap();
             assert_eq!(rx2.recv().unwrap(), 2);
         });
@@ -1956,11 +1910,12 @@ fn oneshot_single_thread_send_port_close() {
     #[test]
     fn oneshot_single_thread_recv_chan_close() {
         // Receiving on a closed chan will panic
-        let res = thread::spawn(move|| {
+        let res = thread::spawn(move || {
             let (tx, rx) = channel::<i32>();
             drop(tx);
             rx.recv().unwrap();
-        }).join();
+        })
+        .join();
         // What is our res?
         assert!(res.is_err());
     }
@@ -2025,7 +1980,7 @@ fn oneshot_single_thread_peek_open() {
     #[test]
     fn oneshot_multi_task_recv_then_send() {
         let (tx, rx) = channel::<Box<i32>>();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             assert!(*rx.recv().unwrap() == 10);
         });
 
@@ -2035,12 +1990,13 @@ fn oneshot_multi_task_recv_then_send() {
     #[test]
     fn oneshot_multi_task_recv_then_close() {
         let (tx, rx) = channel::<Box<i32>>();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             drop(tx);
         });
-        let res = thread::spawn(move|| {
+        let res = thread::spawn(move || {
             assert!(*rx.recv().unwrap() == 10);
-        }).join();
+        })
+        .join();
         assert!(res.is_err());
     }
 
@@ -2048,7 +2004,7 @@ fn oneshot_multi_task_recv_then_close() {
     fn oneshot_multi_thread_close_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = channel::<i32>();
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 drop(rx);
             });
             drop(tx);
@@ -2059,12 +2015,13 @@ fn oneshot_multi_thread_close_stress() {
     fn oneshot_multi_thread_send_close_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = channel::<i32>();
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 drop(rx);
             });
-            let _ = thread::spawn(move|| {
+            let _ = thread::spawn(move || {
                 tx.send(1).unwrap();
-            }).join();
+            })
+            .join();
         }
     }
 
@@ -2072,14 +2029,15 @@ fn oneshot_multi_thread_send_close_stress() {
     fn oneshot_multi_thread_recv_close_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = channel::<i32>();
-            thread::spawn(move|| {
-                let res = thread::spawn(move|| {
+            thread::spawn(move || {
+                let res = thread::spawn(move || {
                     rx.recv().unwrap();
-                }).join();
+                })
+                .join();
                 assert!(res.is_err());
             });
-            let _t = thread::spawn(move|| {
-                thread::spawn(move|| {
+            let _t = thread::spawn(move || {
+                thread::spawn(move || {
                     drop(tx);
                 });
             });
@@ -2090,7 +2048,7 @@ fn oneshot_multi_thread_recv_close_stress() {
     fn oneshot_multi_thread_send_recv_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = channel::<Box<isize>>();
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 tx.send(box 10).unwrap();
             });
             assert!(*rx.recv().unwrap() == 10);
@@ -2106,18 +2064,22 @@ fn stream_send_recv_stress() {
             recv(rx, 0);
 
             fn send(tx: Sender<Box<i32>>, i: i32) {
-                if i == 10 { return }
+                if i == 10 {
+                    return;
+                }
 
-                thread::spawn(move|| {
+                thread::spawn(move || {
                     tx.send(box i).unwrap();
                     send(tx, i + 1);
                 });
             }
 
             fn recv(rx: Receiver<Box<i32>>, i: i32) {
-                if i == 10 { return }
+                if i == 10 {
+                    return;
+                }
 
-                thread::spawn(move|| {
+                thread::spawn(move || {
                     assert!(*rx.recv().unwrap() == i);
                     recv(rx, i + 1);
                 });
@@ -2214,9 +2176,8 @@ fn stress_recv_timeout_shared() {
     #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
     fn very_long_recv_timeout_wont_panic() {
         let (tx, rx) = channel::<()>();
-        let join_handle = thread::spawn(move || {
-            rx.recv_timeout(Duration::from_secs(u64::max_value()))
-        });
+        let join_handle =
+            thread::spawn(move || rx.recv_timeout(Duration::from_secs(u64::max_value())));
         thread::sleep(Duration::from_secs(1));
         assert!(tx.send(()).is_ok());
         assert_eq!(join_handle.join().unwrap(), Ok(()));
@@ -2226,8 +2187,12 @@ fn very_long_recv_timeout_wont_panic() {
     fn recv_a_lot() {
         // Regression test that we don't run out of stack in scheduler context
         let (tx, rx) = channel();
-        for _ in 0..10000 { tx.send(()).unwrap(); }
-        for _ in 0..10000 { rx.recv().unwrap(); }
+        for _ in 0..10000 {
+            tx.send(()).unwrap();
+        }
+        for _ in 0..10000 {
+            rx.recv().unwrap();
+        }
     }
 
     #[test]
@@ -2237,12 +2202,14 @@ fn shared_recv_timeout() {
         let total = 5;
         for _ in 0..total {
             let tx = tx.clone();
-            thread::spawn(move|| {
+            thread::spawn(move || {
                 tx.send(()).unwrap();
             });
         }
 
-        for _ in 0..total { rx.recv().unwrap(); }
+        for _ in 0..total {
+            rx.recv().unwrap();
+        }
 
         assert_eq!(rx.recv_timeout(Duration::from_millis(1)), Err(RecvTimeoutError::Timeout));
         tx.send(()).unwrap();
@@ -2255,7 +2222,7 @@ fn shared_chan_stress() {
         let total = stress_factor() + 100;
         for _ in 0..total {
             let tx = tx.clone();
-            thread::spawn(move|| {
+            thread::spawn(move || {
                 tx.send(()).unwrap();
             });
         }
@@ -2270,7 +2237,7 @@ fn test_nested_recv_iter() {
         let (tx, rx) = channel::<i32>();
         let (total_tx, total_rx) = channel::<i32>();
 
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             let mut acc = 0;
             for x in rx.iter() {
                 acc += x;
@@ -2290,7 +2257,7 @@ fn test_recv_iter_break() {
         let (tx, rx) = channel::<i32>();
         let (count_tx, count_rx) = channel();
 
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             let mut count = 0;
             for x in rx.iter() {
                 if count >= 3 {
@@ -2316,7 +2283,7 @@ fn test_recv_try_iter() {
         let (response_tx, response_rx) = channel();
 
         // Request `x`s until we have `6`.
-        let t = thread::spawn(move|| {
+        let t = thread::spawn(move || {
             let mut count = 0;
             loop {
                 for x in response_rx.try_iter() {
@@ -2341,11 +2308,11 @@ fn test_recv_try_iter() {
     #[test]
     fn test_recv_into_iter_owned() {
         let mut iter = {
-          let (tx, rx) = channel::<i32>();
-          tx.send(1).unwrap();
-          tx.send(2).unwrap();
+            let (tx, rx) = channel::<i32>();
+            tx.send(1).unwrap();
+            tx.send(2).unwrap();
 
-          rx.into_iter()
+            rx.into_iter()
         };
         assert_eq!(iter.next().unwrap(), 1);
         assert_eq!(iter.next().unwrap(), 2);
@@ -2369,7 +2336,7 @@ fn try_recv_states() {
         let (tx1, rx1) = channel::<i32>();
         let (tx2, rx2) = channel::<()>();
         let (tx3, rx3) = channel::<()>();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx2.recv().unwrap();
             tx1.send(1).unwrap();
             tx3.send(()).unwrap();
@@ -2394,13 +2361,15 @@ fn try_recv_states() {
     fn destroy_upgraded_shared_port_when_sender_still_active() {
         let (tx, rx) = channel();
         let (tx2, rx2) = channel();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx.recv().unwrap(); // wait on a oneshot
-            drop(rx);  // destroy a shared
+            drop(rx); // destroy a shared
             tx2.send(()).unwrap();
         });
         // make sure the other thread has gone to sleep
-        for _ in 0..5000 { thread::yield_now(); }
+        for _ in 0..5000 {
+            thread::yield_now();
+        }
 
         // upgrade to a shared chan and send a message
         let t = tx.clone();
@@ -2468,7 +2437,7 @@ fn recv_timeout() {
     #[test]
     fn smoke_threads() {
         let (tx, rx) = sync_channel::<i32>(0);
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             tx.send(1).unwrap();
         });
         assert_eq!(rx.recv().unwrap(), 1);
@@ -2493,7 +2462,7 @@ fn smoke_shared_port_gone2() {
     #[test]
     fn port_gone_concurrent() {
         let (tx, rx) = sync_channel::<i32>(0);
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx.recv().unwrap();
         });
         while tx.send(1).is_ok() {}
@@ -2503,7 +2472,7 @@ fn port_gone_concurrent() {
     fn port_gone_concurrent_shared() {
         let (tx, rx) = sync_channel::<i32>(0);
         let tx2 = tx.clone();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx.recv().unwrap();
         });
         while tx.send(1).is_ok() && tx2.send(1).is_ok() {}
@@ -2528,7 +2497,7 @@ fn smoke_chan_gone_shared() {
     #[test]
     fn chan_gone_concurrent() {
         let (tx, rx) = sync_channel::<i32>(0);
-        thread::spawn(move|| {
+        thread::spawn(move || {
             tx.send(1).unwrap();
             tx.send(1).unwrap();
         });
@@ -2538,8 +2507,10 @@ fn chan_gone_concurrent() {
     #[test]
     fn stress() {
         let (tx, rx) = sync_channel::<i32>(0);
-        thread::spawn(move|| {
-            for _ in 0..10000 { tx.send(1).unwrap(); }
+        thread::spawn(move || {
+            for _ in 0..10000 {
+                tx.send(1).unwrap();
+            }
         });
         for _ in 0..10000 {
             assert_eq!(rx.recv().unwrap(), 1);
@@ -2551,8 +2522,10 @@ fn stress() {
     fn stress_recv_timeout_two_threads() {
         let (tx, rx) = sync_channel::<i32>(0);
 
-        thread::spawn(move|| {
-            for _ in 0..10000 { tx.send(1).unwrap(); }
+        thread::spawn(move || {
+            for _ in 0..10000 {
+                tx.send(1).unwrap();
+            }
         });
 
         let mut recv_count = 0;
@@ -2561,7 +2534,7 @@ fn stress_recv_timeout_two_threads() {
                 Ok(v) => {
                     assert_eq!(v, 1);
                     recv_count += 1;
-                },
+                }
                 Err(RecvTimeoutError::Timeout) => continue,
                 Err(RecvTimeoutError::Disconnected) => break,
             }
@@ -2578,14 +2551,14 @@ fn stress_recv_timeout_shared() {
         let (tx, rx) = sync_channel::<i32>(0);
         let (dtx, drx) = sync_channel::<()>(0);
 
-        thread::spawn(move|| {
+        thread::spawn(move || {
             let mut recv_count = 0;
             loop {
                 match rx.recv_timeout(Duration::from_millis(10)) {
                     Ok(v) => {
                         assert_eq!(v, 1);
                         recv_count += 1;
-                    },
+                    }
                     Err(RecvTimeoutError::Timeout) => continue,
                     Err(RecvTimeoutError::Disconnected) => break,
                 }
@@ -2599,8 +2572,10 @@ fn stress_recv_timeout_shared() {
 
         for _ in 0..NTHREADS {
             let tx = tx.clone();
-            thread::spawn(move|| {
-                for _ in 0..AMT { tx.send(1).unwrap(); }
+            thread::spawn(move || {
+                for _ in 0..AMT {
+                    tx.send(1).unwrap();
+                }
             });
         }
 
@@ -2616,7 +2591,7 @@ fn stress_shared() {
         let (tx, rx) = sync_channel::<i32>(0);
         let (dtx, drx) = sync_channel::<()>(0);
 
-        thread::spawn(move|| {
+        thread::spawn(move || {
             for _ in 0..AMT * NTHREADS {
                 assert_eq!(rx.recv().unwrap(), 1);
             }
@@ -2629,8 +2604,10 @@ fn stress_shared() {
 
         for _ in 0..NTHREADS {
             let tx = tx.clone();
-            thread::spawn(move|| {
-                for _ in 0..AMT { tx.send(1).unwrap(); }
+            thread::spawn(move || {
+                for _ in 0..AMT {
+                    tx.send(1).unwrap();
+                }
             });
         }
         drop(tx);
@@ -2662,11 +2639,12 @@ fn oneshot_single_thread_send_port_close() {
     #[test]
     fn oneshot_single_thread_recv_chan_close() {
         // Receiving on a closed chan will panic
-        let res = thread::spawn(move|| {
+        let res = thread::spawn(move || {
             let (tx, rx) = sync_channel::<i32>(0);
             drop(tx);
             rx.recv().unwrap();
-        }).join();
+        })
+        .join();
         // What is our res?
         assert!(res.is_err());
     }
@@ -2746,7 +2724,7 @@ fn oneshot_single_thread_peek_open() {
     #[test]
     fn oneshot_multi_task_recv_then_send() {
         let (tx, rx) = sync_channel::<Box<i32>>(0);
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             assert!(*rx.recv().unwrap() == 10);
         });
 
@@ -2756,12 +2734,13 @@ fn oneshot_multi_task_recv_then_send() {
     #[test]
     fn oneshot_multi_task_recv_then_close() {
         let (tx, rx) = sync_channel::<Box<i32>>(0);
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             drop(tx);
         });
-        let res = thread::spawn(move|| {
+        let res = thread::spawn(move || {
             assert!(*rx.recv().unwrap() == 10);
-        }).join();
+        })
+        .join();
         assert!(res.is_err());
     }
 
@@ -2769,7 +2748,7 @@ fn oneshot_multi_task_recv_then_close() {
     fn oneshot_multi_thread_close_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<i32>(0);
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 drop(rx);
             });
             drop(tx);
@@ -2780,12 +2759,13 @@ fn oneshot_multi_thread_close_stress() {
     fn oneshot_multi_thread_send_close_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<i32>(0);
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 drop(rx);
             });
             let _ = thread::spawn(move || {
                 tx.send(1).unwrap();
-            }).join();
+            })
+            .join();
         }
     }
 
@@ -2793,14 +2773,15 @@ fn oneshot_multi_thread_send_close_stress() {
     fn oneshot_multi_thread_recv_close_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<i32>(0);
-            let _t = thread::spawn(move|| {
-                let res = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
+                let res = thread::spawn(move || {
                     rx.recv().unwrap();
-                }).join();
+                })
+                .join();
                 assert!(res.is_err());
             });
-            let _t = thread::spawn(move|| {
-                thread::spawn(move|| {
+            let _t = thread::spawn(move || {
+                thread::spawn(move || {
                     drop(tx);
                 });
             });
@@ -2811,7 +2792,7 @@ fn oneshot_multi_thread_recv_close_stress() {
     fn oneshot_multi_thread_send_recv_stress() {
         for _ in 0..stress_factor() {
             let (tx, rx) = sync_channel::<Box<i32>>(0);
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 tx.send(box 10).unwrap();
             });
             assert!(*rx.recv().unwrap() == 10);
@@ -2827,18 +2808,22 @@ fn stream_send_recv_stress() {
             recv(rx, 0);
 
             fn send(tx: SyncSender<Box<i32>>, i: i32) {
-                if i == 10 { return }
+                if i == 10 {
+                    return;
+                }
 
-                thread::spawn(move|| {
+                thread::spawn(move || {
                     tx.send(box i).unwrap();
                     send(tx, i + 1);
                 });
             }
 
             fn recv(rx: Receiver<Box<i32>>, i: i32) {
-                if i == 10 { return }
+                if i == 10 {
+                    return;
+                }
 
-                thread::spawn(move|| {
+                thread::spawn(move || {
                     assert!(*rx.recv().unwrap() == i);
                     recv(rx, i + 1);
                 });
@@ -2850,8 +2835,12 @@ fn recv(rx: Receiver<Box<i32>>, i: i32) {
     fn recv_a_lot() {
         // Regression test that we don't run out of stack in scheduler context
         let (tx, rx) = sync_channel(10000);
-        for _ in 0..10000 { tx.send(()).unwrap(); }
-        for _ in 0..10000 { rx.recv().unwrap(); }
+        for _ in 0..10000 {
+            tx.send(()).unwrap();
+        }
+        for _ in 0..10000 {
+            rx.recv().unwrap();
+        }
     }
 
     #[test]
@@ -2860,7 +2849,7 @@ fn shared_chan_stress() {
         let total = stress_factor() + 100;
         for _ in 0..total {
             let tx = tx.clone();
-            thread::spawn(move|| {
+            thread::spawn(move || {
                 tx.send(()).unwrap();
             });
         }
@@ -2875,7 +2864,7 @@ fn test_nested_recv_iter() {
         let (tx, rx) = sync_channel::<i32>(0);
         let (total_tx, total_rx) = sync_channel::<i32>(0);
 
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             let mut acc = 0;
             for x in rx.iter() {
                 acc += x;
@@ -2895,7 +2884,7 @@ fn test_recv_iter_break() {
         let (tx, rx) = sync_channel::<i32>(0);
         let (count_tx, count_rx) = sync_channel(0);
 
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             let mut count = 0;
             for x in rx.iter() {
                 if count >= 3 {
@@ -2920,7 +2909,7 @@ fn try_recv_states() {
         let (tx1, rx1) = sync_channel::<i32>(1);
         let (tx2, rx2) = sync_channel::<()>(1);
         let (tx3, rx3) = sync_channel::<()>(1);
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx2.recv().unwrap();
             tx1.send(1).unwrap();
             tx3.send(()).unwrap();
@@ -2945,13 +2934,15 @@ fn try_recv_states() {
     fn destroy_upgraded_shared_port_when_sender_still_active() {
         let (tx, rx) = sync_channel::<()>(0);
         let (tx2, rx2) = sync_channel::<()>(0);
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             rx.recv().unwrap(); // wait on a oneshot
-            drop(rx);  // destroy a shared
+            drop(rx); // destroy a shared
             tx2.send(()).unwrap();
         });
         // make sure the other thread has gone to sleep
-        for _ in 0..5000 { thread::yield_now(); }
+        for _ in 0..5000 {
+            thread::yield_now();
+        }
 
         // upgrade to a shared chan and send a message
         let t = tx.clone();
@@ -2965,14 +2956,18 @@ fn destroy_upgraded_shared_port_when_sender_still_active() {
     #[test]
     fn send1() {
         let (tx, rx) = sync_channel::<i32>(0);
-        let _t = thread::spawn(move|| { rx.recv().unwrap(); });
+        let _t = thread::spawn(move || {
+            rx.recv().unwrap();
+        });
         assert_eq!(tx.send(1), Ok(()));
     }
 
     #[test]
     fn send2() {
         let (tx, rx) = sync_channel::<i32>(0);
-        let _t = thread::spawn(move|| { drop(rx); });
+        let _t = thread::spawn(move || {
+            drop(rx);
+        });
         assert!(tx.send(1).is_err());
     }
 
@@ -2980,7 +2975,9 @@ fn send2() {
     fn send3() {
         let (tx, rx) = sync_channel::<i32>(1);
         assert_eq!(tx.send(1), Ok(()));
-        let _t =thread::spawn(move|| { drop(rx); });
+        let _t = thread::spawn(move || {
+            drop(rx);
+        });
         assert!(tx.send(1).is_err());
     }
 
@@ -2990,11 +2987,11 @@ fn send4() {
         let tx2 = tx.clone();
         let (done, donerx) = channel();
         let done2 = done.clone();
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             assert!(tx.send(1).is_err());
             done.send(()).unwrap();
         });
-        let _t = thread::spawn(move|| {
+        let _t = thread::spawn(move || {
             assert!(tx2.send(2).is_err());
             done2.send(()).unwrap();
         });
@@ -3030,7 +3027,7 @@ fn repro() {
             let (tx1, rx1) = sync_channel::<()>(3);
             let (tx2, rx2) = sync_channel::<()>(3);
 
-            let _t = thread::spawn(move|| {
+            let _t = thread::spawn(move || {
                 rx1.recv().unwrap();
                 tx2.try_send(()).unwrap();
             });