diff --git a/crossbeam-channel/benches/crossbeam.rs b/crossbeam-channel/benches/crossbeam.rs index 1c0522294..8f328bc32 100644 --- a/crossbeam-channel/benches/crossbeam.rs +++ b/crossbeam-channel/benches/crossbeam.rs @@ -64,8 +64,7 @@ mod unbounded { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -93,8 +92,7 @@ mod unbounded { r2.recv().unwrap(); }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -129,8 +127,7 @@ mod unbounded { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -165,8 +162,7 @@ mod unbounded { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -208,8 +204,7 @@ mod unbounded { } }); drop(s1); - }) - .unwrap(); + }); } } @@ -241,8 +236,7 @@ mod bounded_n { r2.recv().unwrap(); }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -277,8 +271,7 @@ mod bounded_n { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -313,8 +306,7 @@ mod bounded_n { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -347,8 +339,7 @@ mod bounded_n { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -391,8 +382,7 @@ mod bounded_n { } }); drop(s1); - }) - .unwrap(); + }); } } @@ -438,8 +428,7 @@ mod bounded_1 { r2.recv().unwrap(); }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -474,8 +463,7 @@ mod bounded_1 { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -510,8 +498,7 @@ mod bounded_1 { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -553,8 +540,7 @@ mod bounded_1 { } }); drop(s1); - }) - .unwrap(); + }); } } @@ -591,8 +577,7 @@ mod bounded_0 { r2.recv().unwrap(); }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -627,8 +612,7 @@ mod bounded_0 { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -663,8 +647,7 @@ mod bounded_0 { } }); drop(s1); - }) - .unwrap(); + }); } #[bench] @@ -706,7 +689,6 @@ mod bounded_0 { } }); drop(s1); - }) - .unwrap(); + }); } } diff --git a/crossbeam-channel/benchmarks/atomicring.rs b/crossbeam-channel/benchmarks/atomicring.rs index 78cd6fcc8..437e5846f 100644 --- a/crossbeam-channel/benchmarks/atomicring.rs +++ b/crossbeam-channel/benchmarks/atomicring.rs @@ -49,8 +49,7 @@ fn spsc(cap: usize) { } } } - }) - .unwrap(); + }); } fn mpsc(cap: usize) { @@ -80,8 +79,7 @@ fn mpsc(cap: usize) { } } } - }) - .unwrap(); + }); } fn mpmc(cap: usize) { @@ -114,8 +112,7 @@ fn mpmc(cap: usize) { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/atomicringqueue.rs b/crossbeam-channel/benchmarks/atomicringqueue.rs index f0b97727a..37319c342 100644 --- a/crossbeam-channel/benchmarks/atomicringqueue.rs +++ b/crossbeam-channel/benchmarks/atomicringqueue.rs @@ -43,8 +43,7 @@ fn spsc(cap: usize) { for _ in 0..MESSAGES { q.pop(); } - }) - .unwrap(); + }); } fn mpsc(cap: usize) { @@ -68,8 +67,7 @@ fn mpsc(cap: usize) { for _ in 0..MESSAGES { q.pop(); } - }) - .unwrap(); + }); } fn mpmc(cap: usize) { @@ -97,8 +95,7 @@ fn mpmc(cap: usize) { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/bus.rs b/crossbeam-channel/benchmarks/bus.rs index 754f32db8..17701339d 100644 --- a/crossbeam-channel/benchmarks/bus.rs +++ b/crossbeam-channel/benchmarks/bus.rs @@ -31,8 +31,7 @@ fn spsc(cap: usize) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/chan.rs b/crossbeam-channel/benchmarks/chan.rs index 17f4d9932..b0e5966d9 100644 --- a/crossbeam-channel/benchmarks/chan.rs +++ b/crossbeam-channel/benchmarks/chan.rs @@ -37,8 +37,7 @@ fn spsc(cap: Option) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpsc(cap: Option) { @@ -56,8 +55,7 @@ fn mpsc(cap: Option) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpmc(cap: Option) { @@ -79,8 +77,7 @@ fn mpmc(cap: Option) { } }); } - }) - .unwrap(); + }); } fn select_rx(cap: Option) { @@ -109,8 +106,7 @@ fn select_rx(cap: Option) { rx3.recv() -> m => assert!(m.is_some()), } } - }) - .unwrap(); + }); } fn select_both(cap: Option) { @@ -155,8 +151,7 @@ fn select_both(cap: Option) { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/crossbeam-channel.rs b/crossbeam-channel/benchmarks/crossbeam-channel.rs index 506e1b230..7f0b7dd08 100644 --- a/crossbeam-channel/benchmarks/crossbeam-channel.rs +++ b/crossbeam-channel/benchmarks/crossbeam-channel.rs @@ -37,8 +37,7 @@ fn spsc(cap: Option) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpsc(cap: Option) { @@ -56,8 +55,7 @@ fn mpsc(cap: Option) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpmc(cap: Option) { @@ -79,8 +77,7 @@ fn mpmc(cap: Option) { } }); } - }) - .unwrap(); + }); } fn select_rx(cap: Option) { @@ -105,8 +102,7 @@ fn select_rx(cap: Option) { let index = case.index(); case.recv(&chans[index].1).unwrap(); } - }) - .unwrap(); + }); } fn select_both(cap: Option) { @@ -140,8 +136,7 @@ fn select_both(cap: Option) { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/crossbeam-deque.rs b/crossbeam-channel/benchmarks/crossbeam-deque.rs index 935c1fb77..2f74227d4 100644 --- a/crossbeam-channel/benchmarks/crossbeam-deque.rs +++ b/crossbeam-channel/benchmarks/crossbeam-deque.rs @@ -43,8 +43,7 @@ fn spsc() { } } }); - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/flume.rs b/crossbeam-channel/benchmarks/flume.rs index 06b942105..af27bca13 100644 --- a/crossbeam-channel/benchmarks/flume.rs +++ b/crossbeam-channel/benchmarks/flume.rs @@ -75,8 +75,7 @@ fn spsc_unbounded() { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn spsc_bounded(cap: usize) { @@ -92,8 +91,7 @@ fn spsc_bounded(cap: usize) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpsc_unbounded() { @@ -112,8 +110,7 @@ fn mpsc_unbounded() { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpsc_bounded(cap: usize) { @@ -132,8 +129,7 @@ fn mpsc_bounded(cap: usize) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/lockfree.rs b/crossbeam-channel/benchmarks/lockfree.rs index 3ae0a0e03..d6ddcda80 100644 --- a/crossbeam-channel/benchmarks/lockfree.rs +++ b/crossbeam-channel/benchmarks/lockfree.rs @@ -36,8 +36,7 @@ fn spsc() { thread::yield_now(); } } - }) - .unwrap(); + }); } fn mpsc() { @@ -57,8 +56,7 @@ fn mpsc() { thread::yield_now(); } } - }) - .unwrap(); + }); } fn mpmc() { @@ -82,8 +80,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/mpmc.rs b/crossbeam-channel/benchmarks/mpmc.rs index 30a41dc98..869c688fb 100644 --- a/crossbeam-channel/benchmarks/mpmc.rs +++ b/crossbeam-channel/benchmarks/mpmc.rs @@ -48,8 +48,7 @@ fn spsc(cap: usize) { } } } - }) - .unwrap(); + }); } fn mpsc(cap: usize) { @@ -79,8 +78,7 @@ fn mpsc(cap: usize) { } } } - }) - .unwrap(); + }); } fn mpmc(cap: usize) { @@ -114,8 +112,7 @@ fn mpmc(cap: usize) { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/mpsc.rs b/crossbeam-channel/benchmarks/mpsc.rs index 728fdd39a..e80b7cf05 100644 --- a/crossbeam-channel/benchmarks/mpsc.rs +++ b/crossbeam-channel/benchmarks/mpsc.rs @@ -77,8 +77,7 @@ fn spsc_async() { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn spsc_sync(cap: usize) { @@ -94,8 +93,7 @@ fn spsc_sync(cap: usize) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpsc_async() { @@ -114,8 +112,7 @@ fn mpsc_async() { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn mpsc_sync(cap: usize) { @@ -134,8 +131,7 @@ fn mpsc_sync(cap: usize) { for _ in 0..MESSAGES { rx.recv().unwrap(); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/benchmarks/segqueue.rs b/crossbeam-channel/benchmarks/segqueue.rs index 809a3f4cc..713d0bd00 100644 --- a/crossbeam-channel/benchmarks/segqueue.rs +++ b/crossbeam-channel/benchmarks/segqueue.rs @@ -37,8 +37,7 @@ fn spsc() { } } } - }) - .unwrap(); + }); } fn mpsc() { @@ -62,8 +61,7 @@ fn mpsc() { } } } - }) - .unwrap(); + }); } fn mpmc() { @@ -91,8 +89,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); } fn main() { diff --git a/crossbeam-channel/examples/matching.rs b/crossbeam-channel/examples/matching.rs index 5421169b9..42dccd11e 100644 --- a/crossbeam-channel/examples/matching.rs +++ b/crossbeam-channel/examples/matching.rs @@ -62,8 +62,7 @@ fn main() { let (s, r) = (s.clone(), r.clone()); scope.spawn(move |_| seek(name, s, r)); } - }) - .unwrap(); + }); // Check if there is a pending send operation. if let Ok(name) = r.try_recv() { diff --git a/crossbeam-channel/src/lib.rs b/crossbeam-channel/src/lib.rs index cc1ef112f..ff10f72c2 100644 --- a/crossbeam-channel/src/lib.rs +++ b/crossbeam-channel/src/lib.rs @@ -137,7 +137,7 @@ //! // Send a message and then receive one. //! s.send(1).unwrap(); //! r.recv().unwrap(); -//! }).unwrap(); +//! }); //! ``` //! //! # Disconnection diff --git a/crossbeam-channel/tests/after.rs b/crossbeam-channel/tests/after.rs index 678a8c679..7adbeda70 100644 --- a/crossbeam-channel/tests/after.rs +++ b/crossbeam-channel/tests/after.rs @@ -146,8 +146,7 @@ fn recv_two() { recv(r2) -> _ => {} } }); - }) - .unwrap(); + }); } #[test] @@ -220,8 +219,7 @@ fn select() { } }); } - }) - .unwrap(); + }); assert_eq!(hits.load(Ordering::SeqCst), COUNT); } @@ -263,8 +261,7 @@ fn ready() { } }); } - }) - .unwrap(); + }); assert_eq!(hits.load(Ordering::SeqCst), COUNT); } @@ -290,8 +287,7 @@ fn stress_clone() { } }); } - }) - .unwrap(); + }); } } diff --git a/crossbeam-channel/tests/array.rs b/crossbeam-channel/tests/array.rs index 970c5c175..c4b62a29f 100644 --- a/crossbeam-channel/tests/array.rs +++ b/crossbeam-channel/tests/array.rs @@ -93,8 +93,7 @@ fn try_recv() { thread::sleep(ms(1000)); s.send(7).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -116,8 +115,7 @@ fn recv() { s.send(8).unwrap(); s.send(9).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -137,8 +135,7 @@ fn recv_timeout() { thread::sleep(ms(1500)); s.send(7).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -160,8 +157,7 @@ fn try_send() { assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); assert_eq!(r.recv(), Ok(3)); }); - }) - .unwrap(); + }); } #[test] @@ -184,8 +180,7 @@ fn send() { assert_eq!(r.recv(), Ok(8)); assert_eq!(r.recv(), Ok(9)); }); - }) - .unwrap(); + }); } #[test] @@ -212,8 +207,7 @@ fn send_timeout() { assert_eq!(r.recv(), Ok(2)); assert_eq!(r.recv(), Ok(4)); }); - }) - .unwrap(); + }); } #[test] @@ -309,8 +303,7 @@ fn len() { assert!(len <= CAP); } }); - }) - .unwrap(); + }); assert_eq!(s.len(), 0); assert_eq!(r.len(), 0); @@ -329,8 +322,7 @@ fn disconnect_wakes_sender() { thread::sleep(ms(1000)); drop(r); }); - }) - .unwrap(); + }); } #[test] @@ -345,8 +337,7 @@ fn disconnect_wakes_receiver() { thread::sleep(ms(1000)); drop(s); }); - }) - .unwrap(); + }); } #[test] @@ -370,8 +361,7 @@ fn spsc() { s.send(i).unwrap(); } }); - }) - .unwrap(); + }); } #[test] @@ -401,8 +391,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(Ordering::SeqCst), THREADS); @@ -422,8 +411,7 @@ fn stress_oneshot() { scope(|scope| { scope.spawn(|_| r.recv().unwrap()); scope.spawn(|_| s.send(0).unwrap()); - }) - .unwrap(); + }); } } @@ -456,8 +444,7 @@ fn stress_iter() { break; } } - }) - .unwrap(); + }); } #[test] @@ -493,8 +480,7 @@ fn stress_timeout_two_threads() { } } }); - }) - .unwrap(); + }); } #[test] @@ -544,8 +530,7 @@ fn drops() { std::thread::yield_now(); // https://github.com/rust-lang/miri/issues/1388 } }); - }) - .unwrap(); + }); for _ in 0..additional { s.send(DropCounter).unwrap(); @@ -577,8 +562,7 @@ fn linearizable() { } }); } - }) - .unwrap(); + }); } #[test] @@ -690,8 +674,7 @@ fn channel_through_channel() { .unwrap() } }); - }) - .unwrap(); + }); } #[test] diff --git a/crossbeam-channel/tests/iter.rs b/crossbeam-channel/tests/iter.rs index 463f3b043..16f0e6c35 100644 --- a/crossbeam-channel/tests/iter.rs +++ b/crossbeam-channel/tests/iter.rs @@ -22,8 +22,7 @@ fn nested_recv_iter() { s.send(2).unwrap(); drop(s); assert_eq!(total_r.recv().unwrap(), 6); - }) - .unwrap(); + }); } #[test] @@ -50,8 +49,7 @@ fn recv_iter_break() { let _ = s.send(2); drop(s); assert_eq!(count_r.recv().unwrap(), 4); - }) - .unwrap(); + }); } #[test] @@ -78,8 +76,7 @@ fn recv_try_iter() { break; } } - }) - .unwrap(); + }); } #[test] diff --git a/crossbeam-channel/tests/list.rs b/crossbeam-channel/tests/list.rs index 1cf3699ee..3e2210384 100644 --- a/crossbeam-channel/tests/list.rs +++ b/crossbeam-channel/tests/list.rs @@ -82,8 +82,7 @@ fn try_recv() { thread::sleep(ms(1000)); s.send(7).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -105,8 +104,7 @@ fn recv() { s.send(8).unwrap(); s.send(9).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -126,8 +124,7 @@ fn recv_timeout() { thread::sleep(ms(1500)); s.send(7).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -233,8 +230,7 @@ fn disconnect_wakes_receiver() { thread::sleep(ms(1000)); drop(s); }); - }) - .unwrap(); + }); } #[test] @@ -258,8 +254,7 @@ fn spsc() { s.send(i).unwrap(); } }); - }) - .unwrap(); + }); } #[test] @@ -289,8 +284,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); @@ -312,8 +306,7 @@ fn stress_oneshot() { scope(|scope| { scope.spawn(|_| r.recv().unwrap()); scope.spawn(|_| s.send(0).unwrap()); - }) - .unwrap(); + }); } } @@ -346,8 +339,7 @@ fn stress_iter() { break; } } - }) - .unwrap(); + }); } #[test] @@ -379,8 +371,7 @@ fn stress_timeout_two_threads() { } } }); - }) - .unwrap(); + }); } #[test] @@ -428,8 +419,7 @@ fn drops() { s.send(DropCounter).unwrap(); } }); - }) - .unwrap(); + }); for _ in 0..additional { s.try_send(DropCounter).unwrap(); @@ -461,8 +451,7 @@ fn linearizable() { } }); } - }) - .unwrap(); + }); } #[test] @@ -563,6 +552,5 @@ fn channel_through_channel() { .unwrap() } }); - }) - .unwrap(); + }); } diff --git a/crossbeam-channel/tests/ready.rs b/crossbeam-channel/tests/ready.rs index d8dd6ceb5..6f2be4449 100644 --- a/crossbeam-channel/tests/ready.rs +++ b/crossbeam-channel/tests/ready.rs @@ -78,8 +78,7 @@ fn disconnected() { } r2.recv().unwrap(); - }) - .unwrap(); + }); let mut sel = Select::new(); sel.recv(&r1); @@ -101,8 +100,7 @@ fn disconnected() { Ok(0) => assert_eq!(r2.try_recv(), Err(TryRecvError::Disconnected)), _ => panic!(), } - }) - .unwrap(); + }); } #[test] @@ -165,8 +163,7 @@ fn timeout() { Ok(1) => assert_eq!(r2.try_recv(), Ok(2)), _ => panic!(), } - }) - .unwrap(); + }); scope(|scope| { let (s, r) = unbounded::(); @@ -185,8 +182,7 @@ fn timeout() { Ok(0) => assert_eq!(r.try_recv(), Err(TryRecvError::Disconnected)), _ => panic!(), } - }) - .unwrap(); + }); } #[test] @@ -263,8 +259,7 @@ fn unblocks() { Ok(1) => assert_eq!(r2.try_recv(), Ok(2)), _ => panic!(), } - }) - .unwrap(); + }); scope(|scope| { scope.spawn(|_| { @@ -284,8 +279,7 @@ fn unblocks() { _ => unreachable!(), }, } - }) - .unwrap(); + }); } #[test] @@ -310,8 +304,7 @@ fn both_ready() { _ => panic!(), } } - }) - .unwrap(); + }); } #[test] @@ -341,8 +334,7 @@ fn cloning1() { } s3.send(()).unwrap(); - }) - .unwrap(); + }); } #[test] @@ -366,8 +358,7 @@ fn cloning2() { thread::sleep(ms(500)); drop(s1.clone()); s2.send(()).unwrap(); - }) - .unwrap(); + }); } #[test] @@ -526,8 +517,7 @@ fn stress_recv() { s3.send(()).unwrap(); } } - }) - .unwrap(); + }); } #[test] @@ -563,8 +553,7 @@ fn stress_send() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } #[test] @@ -600,8 +589,7 @@ fn stress_mixed() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } #[test] @@ -652,8 +640,7 @@ fn stress_timeout_two_threads() { } } }); - }) - .unwrap(); + }); } #[test] @@ -729,8 +716,7 @@ fn channel_through_channel() { r = new; } }); - }) - .unwrap(); + }); } } @@ -847,6 +833,5 @@ fn fairness2() { } } assert!(hits.iter().all(|x| x.get() > 0)); - }) - .unwrap(); + }); } diff --git a/crossbeam-channel/tests/select.rs b/crossbeam-channel/tests/select.rs index f24aed8fc..4c1c50f70 100644 --- a/crossbeam-channel/tests/select.rs +++ b/crossbeam-channel/tests/select.rs @@ -97,8 +97,7 @@ fn disconnected() { } r2.recv().unwrap(); - }) - .unwrap(); + }); let mut sel = Select::new(); let oper1 = sel.recv(&r1); @@ -129,8 +128,7 @@ fn disconnected() { _ => unreachable!(), }, } - }) - .unwrap(); + }); } #[test] @@ -227,8 +225,7 @@ fn timeout() { _ => unreachable!(), }, } - }) - .unwrap(); + }); scope(|scope| { let (s, r) = unbounded::(); @@ -255,8 +252,7 @@ fn timeout() { } Ok(_) => unreachable!(), } - }) - .unwrap(); + }); } #[test] @@ -356,8 +352,7 @@ fn unblocks() { _ => unreachable!(), }, } - }) - .unwrap(); + }); scope(|scope| { scope.spawn(|_| { @@ -377,8 +372,7 @@ fn unblocks() { _ => unreachable!(), }, } - }) - .unwrap(); + }); } #[test] @@ -404,8 +398,7 @@ fn both_ready() { _ => unreachable!(), } } - }) - .unwrap(); + }); } #[cfg_attr(miri, ignore)] // Miri is too slow @@ -500,8 +493,7 @@ fn loop_try() { drop(s_end); }); - }) - .unwrap(); + }); } } @@ -533,8 +525,7 @@ fn cloning1() { } s3.send(()).unwrap(); - }) - .unwrap(); + }); } #[test] @@ -559,8 +550,7 @@ fn cloning2() { thread::sleep(ms(500)); drop(s1.clone()); s2.send(()).unwrap(); - }) - .unwrap(); + }); } #[test] @@ -728,8 +718,7 @@ fn stress_recv() { s3.send(()).unwrap(); } } - }) - .unwrap(); + }); } #[test] @@ -766,8 +755,7 @@ fn stress_send() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } #[test] @@ -804,8 +792,7 @@ fn stress_mixed() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } #[test] @@ -862,8 +849,7 @@ fn stress_timeout_two_threads() { } } }); - }) - .unwrap(); + }); } #[test] @@ -917,8 +903,7 @@ fn matching() { } }); } - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); } @@ -944,8 +929,7 @@ fn matching_with_leftover() { }); } s.send(!0).unwrap(); - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); } @@ -1006,8 +990,7 @@ fn channel_through_channel() { r = new; } }); - }) - .unwrap(); + }); } } @@ -1061,8 +1044,7 @@ fn linearizable_try() { end_r.recv().unwrap(); } - }) - .unwrap(); + }); } } @@ -1116,8 +1098,7 @@ fn linearizable_timeout() { end_r.recv().unwrap(); } - }) - .unwrap(); + }); } } @@ -1228,8 +1209,7 @@ fn fairness2() { } } assert!(hits.iter().all(|x| x.get() >= COUNT / hits.len() / 50)); - }) - .unwrap(); + }); } #[test] @@ -1255,8 +1235,7 @@ fn sync_and_clone() { } }); } - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); } @@ -1283,8 +1262,7 @@ fn send_and_clone() { } }); } - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); } @@ -1324,6 +1302,5 @@ fn reuse() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } diff --git a/crossbeam-channel/tests/select_macro.rs b/crossbeam-channel/tests/select_macro.rs index 0c49cb8c5..dea7d9bf5 100644 --- a/crossbeam-channel/tests/select_macro.rs +++ b/crossbeam-channel/tests/select_macro.rs @@ -75,8 +75,7 @@ fn disconnected() { } r2.recv().unwrap(); - }) - .unwrap(); + }); select! { recv(r1) -> v => assert!(v.is_err()), @@ -94,8 +93,7 @@ fn disconnected() { recv(r2) -> v => assert!(v.is_err()), default(ms(1000)) => panic!(), } - }) - .unwrap(); + }); } #[test] @@ -156,8 +154,7 @@ fn timeout() { recv(r2) -> v => assert_eq!(v, Ok(2)), default(ms(1000)) => panic!(), } - }) - .unwrap(); + }); scope(|scope| { let (s, r) = unbounded::(); @@ -175,8 +172,7 @@ fn timeout() { } } } - }) - .unwrap(); + }); } #[test] @@ -244,8 +240,7 @@ fn unblocks() { recv(r2) -> v => assert_eq!(v, Ok(2)), default(ms(1000)) => panic!(), } - }) - .unwrap(); + }); scope(|scope| { scope.spawn(|_| { @@ -258,8 +253,7 @@ fn unblocks() { send(s2, 2) -> _ => panic!(), default(ms(1000)) => panic!(), } - }) - .unwrap(); + }); } #[test] @@ -280,8 +274,7 @@ fn both_ready() { send(s2, 2) -> _ => {}, } } - }) - .unwrap(); + }); } #[cfg_attr(miri, ignore)] // Miri is too slow @@ -330,8 +323,7 @@ fn loop_try() { drop(s_end); }); - }) - .unwrap(); + }); } } @@ -358,8 +350,7 @@ fn cloning1() { } s3.send(()).unwrap(); - }) - .unwrap(); + }); } #[test] @@ -379,8 +370,7 @@ fn cloning2() { thread::sleep(ms(500)); drop(s1.clone()); s2.send(()).unwrap(); - }) - .unwrap(); + }); } #[test] @@ -517,8 +507,7 @@ fn stress_recv() { s3.send(()).unwrap(); } } - }) - .unwrap(); + }); } #[test] @@ -550,8 +539,7 @@ fn stress_send() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } #[test] @@ -583,8 +571,7 @@ fn stress_mixed() { } s3.send(()).unwrap(); } - }) - .unwrap(); + }); } #[test] @@ -626,8 +613,7 @@ fn stress_timeout_two_threads() { } } }); - }) - .unwrap(); + }); } #[test] @@ -662,8 +648,7 @@ fn matching() { } }); } - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); } @@ -684,8 +669,7 @@ fn matching_with_leftover() { }); } s.send(!0).unwrap(); - }) - .unwrap(); + }); assert_eq!(r.try_recv(), Err(TryRecvError::Empty)); } @@ -733,8 +717,7 @@ fn channel_through_channel() { } } }); - }) - .unwrap(); + }); } } @@ -780,8 +763,7 @@ fn linearizable_default() { end_r.recv().unwrap(); } - }) - .unwrap(); + }); } } @@ -827,8 +809,7 @@ fn linearizable_timeout() { end_r.recv().unwrap(); } - }) - .unwrap(); + }); } } @@ -895,8 +876,7 @@ fn fairness2() { } } assert!(hits.iter().all(|x| x.get() >= COUNT / hits.len() / 50)); - }) - .unwrap(); + }); } #[test] @@ -1269,8 +1249,7 @@ fn try_recv() { send(s, 7) -> res => res.unwrap(), } }); - }) - .unwrap(); + }); } #[test] @@ -1306,8 +1285,7 @@ fn recv() { send(s, 9) -> res => res.unwrap(), } }); - }) - .unwrap(); + }); } #[test] @@ -1335,8 +1313,7 @@ fn recv_timeout() { send(s, 7) -> res => res.unwrap(), } }); - }) - .unwrap(); + }); } #[test] @@ -1366,8 +1343,7 @@ fn try_send() { recv(r) -> v => assert_eq!(v, Ok(8)), } }); - }) - .unwrap(); + }); } #[test] @@ -1400,8 +1376,7 @@ fn send() { recv(r) -> v => assert_eq!(v, Ok(9)), } }); - }) - .unwrap(); + }); } #[test] @@ -1429,8 +1404,7 @@ fn send_timeout() { recv(r) -> v => assert_eq!(v, Ok(8)), } }); - }) - .unwrap(); + }); } #[test] @@ -1447,8 +1421,7 @@ fn disconnect_wakes_sender() { thread::sleep(ms(1000)); drop(r); }); - }) - .unwrap(); + }); } #[test] @@ -1465,8 +1438,7 @@ fn disconnect_wakes_receiver() { thread::sleep(ms(1000)); drop(s); }); - }) - .unwrap(); + }); } #[test] diff --git a/crossbeam-channel/tests/thread_locals.rs b/crossbeam-channel/tests/thread_locals.rs index effb6a143..7e7788d26 100644 --- a/crossbeam-channel/tests/thread_locals.rs +++ b/crossbeam-channel/tests/thread_locals.rs @@ -48,6 +48,5 @@ fn use_while_exiting() { thread::sleep(ms(100)); s.send(()).unwrap(); }); - }) - .unwrap(); + }); } diff --git a/crossbeam-channel/tests/tick.rs b/crossbeam-channel/tests/tick.rs index 23bbb1f18..75a3a98f8 100644 --- a/crossbeam-channel/tests/tick.rs +++ b/crossbeam-channel/tests/tick.rs @@ -176,8 +176,7 @@ fn recv_two() { } } }); - }) - .unwrap(); + }); } #[test] @@ -248,8 +247,7 @@ fn select() { } }); } - }) - .unwrap(); + }); assert_eq!(hits.load(Ordering::SeqCst), 8); } @@ -297,8 +295,7 @@ fn ready() { } }); } - }) - .unwrap(); + }); assert_eq!(hits.load(Ordering::SeqCst), 8); } diff --git a/crossbeam-channel/tests/zero.rs b/crossbeam-channel/tests/zero.rs index 8eb5304f5..370ba7b9e 100644 --- a/crossbeam-channel/tests/zero.rs +++ b/crossbeam-channel/tests/zero.rs @@ -44,8 +44,7 @@ fn len_empty_full() { scope(|scope| { scope.spawn(|_| s.send(0).unwrap()); scope.spawn(|_| r.recv().unwrap()); - }) - .unwrap(); + }); assert_eq!(s.len(), 0); assert!(s.is_empty()); @@ -71,8 +70,7 @@ fn try_recv() { thread::sleep(ms(1000)); s.send(7).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -94,8 +92,7 @@ fn recv() { s.send(8).unwrap(); s.send(9).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -115,8 +112,7 @@ fn recv_timeout() { thread::sleep(ms(1500)); s.send(7).unwrap(); }); - }) - .unwrap(); + }); } #[test] @@ -135,8 +131,7 @@ fn try_send() { thread::sleep(ms(1000)); assert_eq!(r.recv(), Ok(8)); }); - }) - .unwrap(); + }); } #[test] @@ -157,8 +152,7 @@ fn send() { assert_eq!(r.recv(), Ok(8)); assert_eq!(r.recv(), Ok(9)); }); - }) - .unwrap(); + }); } #[test] @@ -181,8 +175,7 @@ fn send_timeout() { thread::sleep(ms(1500)); assert_eq!(r.recv(), Ok(8)); }); - }) - .unwrap(); + }); } #[test] @@ -211,8 +204,7 @@ fn len() { assert_eq!(s.len(), 0); } }); - }) - .unwrap(); + }); assert_eq!(s.len(), 0); assert_eq!(r.len(), 0); @@ -230,8 +222,7 @@ fn disconnect_wakes_sender() { thread::sleep(ms(1000)); drop(r); }); - }) - .unwrap(); + }); } #[test] @@ -246,8 +237,7 @@ fn disconnect_wakes_receiver() { thread::sleep(ms(1000)); drop(s); }); - }) - .unwrap(); + }); } #[test] @@ -271,8 +261,7 @@ fn spsc() { s.send(i).unwrap(); } }); - }) - .unwrap(); + }); } #[test] @@ -302,8 +291,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(Ordering::SeqCst), THREADS); @@ -323,8 +311,7 @@ fn stress_oneshot() { scope(|scope| { scope.spawn(|_| r.recv().unwrap()); scope.spawn(|_| s.send(0).unwrap()); - }) - .unwrap(); + }); } } @@ -355,8 +342,7 @@ fn stress_iter() { break; } } - }) - .unwrap(); + }); } #[test] @@ -392,8 +378,7 @@ fn stress_timeout_two_threads() { } } }); - }) - .unwrap(); + }); } #[test] @@ -438,8 +423,7 @@ fn drops() { s.send(DropCounter).unwrap(); } }); - }) - .unwrap(); + }); assert_eq!(DROPS.load(Ordering::SeqCst), steps); drop(s); @@ -478,8 +462,7 @@ fn fairness() { } } assert!(hits.iter().all(|x| *x >= COUNT / hits.len() / 2)); - }) - .unwrap(); + }); } #[test] @@ -517,8 +500,7 @@ fn fairness_duplicates() { } } assert!(hits.iter().all(|x| *x >= COUNT / hits.len() / 2)); - }) - .unwrap(); + }); } #[test] @@ -539,8 +521,7 @@ fn recv_in_send() { select! { send(s, r.recv().unwrap()) -> _ => {} } - }) - .unwrap(); + }); } #[test] @@ -580,6 +561,5 @@ fn channel_through_channel() { .unwrap() } }); - }) - .unwrap(); + }); } diff --git a/crossbeam-deque/tests/fifo.rs b/crossbeam-deque/tests/fifo.rs index f98737b58..9a2389c2c 100644 --- a/crossbeam-deque/tests/fifo.rs +++ b/crossbeam-deque/tests/fifo.rs @@ -96,8 +96,7 @@ fn spsc() { for i in 0..STEPS { w.push(i); } - }) - .unwrap(); + }); } #[test] @@ -140,8 +139,7 @@ fn stampede() { remaining.fetch_sub(1, SeqCst); } } - }) - .unwrap(); + }); } #[test] @@ -202,8 +200,7 @@ fn stress() { } } done.store(true, SeqCst); - }) - .unwrap(); + }); } #[cfg_attr(miri, ignore)] // Miri is too slow @@ -262,8 +259,7 @@ fn no_starvation() { } } done.store(true, SeqCst); - }) - .unwrap(); + }); } #[test] @@ -332,8 +328,7 @@ fn destructors() { remaining.fetch_sub(1, SeqCst); } } - }) - .unwrap(); + }); let rem = remaining.load(SeqCst); assert!(rem > 0); diff --git a/crossbeam-deque/tests/injector.rs b/crossbeam-deque/tests/injector.rs index f706a8d9c..0ac4a0dae 100644 --- a/crossbeam-deque/tests/injector.rs +++ b/crossbeam-deque/tests/injector.rs @@ -72,8 +72,7 @@ fn spsc() { for i in 0..COUNT { q.push(i); } - }) - .unwrap(); + }); } #[test] @@ -110,8 +109,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(SeqCst), THREADS); @@ -158,8 +156,7 @@ fn stampede() { remaining.fetch_sub(1, SeqCst); } } - }) - .unwrap(); + }); } #[test] @@ -220,8 +217,7 @@ fn stress() { } } done.store(true, SeqCst); - }) - .unwrap(); + }); } #[cfg_attr(miri, ignore)] // Miri is too slow @@ -280,8 +276,7 @@ fn no_starvation() { } } done.store(true, SeqCst); - }) - .unwrap(); + }); } #[test] @@ -350,8 +345,7 @@ fn destructors() { remaining.fetch_sub(1, SeqCst); } } - }) - .unwrap(); + }); let rem = remaining.load(SeqCst); assert!(rem > 0); diff --git a/crossbeam-deque/tests/lifo.rs b/crossbeam-deque/tests/lifo.rs index c1a65cd2e..26cd232ae 100644 --- a/crossbeam-deque/tests/lifo.rs +++ b/crossbeam-deque/tests/lifo.rs @@ -98,8 +98,7 @@ fn spsc() { for i in 0..STEPS { w.push(i); } - }) - .unwrap(); + }); } #[test] @@ -142,8 +141,7 @@ fn stampede() { remaining.fetch_sub(1, SeqCst); } } - }) - .unwrap(); + }); } #[test] @@ -204,8 +202,7 @@ fn stress() { } } done.store(true, SeqCst); - }) - .unwrap(); + }); } #[cfg_attr(miri, ignore)] // Miri is too slow @@ -264,8 +261,7 @@ fn no_starvation() { } } done.store(true, SeqCst); - }) - .unwrap(); + }); } #[test] @@ -334,8 +330,7 @@ fn destructors() { remaining.fetch_sub(1, SeqCst); } } - }) - .unwrap(); + }); let rem = remaining.load(SeqCst); assert!(rem > 0); diff --git a/crossbeam-epoch/benches/defer.rs b/crossbeam-epoch/benches/defer.rs index 246f90798..341597772 100644 --- a/crossbeam-epoch/benches/defer.rs +++ b/crossbeam-epoch/benches/defer.rs @@ -43,8 +43,7 @@ fn multi_alloc_defer_free(b: &mut Bencher) { } }); } - }) - .unwrap(); + }); }); } @@ -63,7 +62,6 @@ fn multi_defer(b: &mut Bencher) { } }); } - }) - .unwrap(); + }); }); } diff --git a/crossbeam-epoch/benches/flush.rs b/crossbeam-epoch/benches/flush.rs index 99aab19e1..6359eeb57 100644 --- a/crossbeam-epoch/benches/flush.rs +++ b/crossbeam-epoch/benches/flush.rs @@ -27,8 +27,7 @@ fn single_flush(b: &mut Bencher) { start.wait(); b.iter(|| epoch::pin().flush()); end.wait(); - }) - .unwrap(); + }); } #[bench] @@ -46,7 +45,6 @@ fn multi_flush(b: &mut Bencher) { } }); } - }) - .unwrap(); + }); }); } diff --git a/crossbeam-epoch/benches/pin.rs b/crossbeam-epoch/benches/pin.rs index 8bf87e9b7..54a863568 100644 --- a/crossbeam-epoch/benches/pin.rs +++ b/crossbeam-epoch/benches/pin.rs @@ -25,7 +25,6 @@ fn multi_pin(b: &mut Bencher) { } }); } - }) - .unwrap(); + }); }); } diff --git a/crossbeam-epoch/src/collector.rs b/crossbeam-epoch/src/collector.rs index 099a2ffc6..8b3517159 100644 --- a/crossbeam-epoch/src/collector.rs +++ b/crossbeam-epoch/src/collector.rs @@ -200,8 +200,7 @@ mod tests { } }); } - }) - .unwrap(); + }); } #[cfg(not(crossbeam_sanitize))] // TODO: assertions failed due to `cfg(crossbeam_sanitize)` reduce `internal::MAX_OBJECTS` @@ -452,8 +451,7 @@ mod tests { } }); } - }) - .unwrap(); + }); let handle = collector.register(); while DROPS.load(Ordering::Relaxed) < COUNT * THREADS { diff --git a/crossbeam-epoch/src/default.rs b/crossbeam-epoch/src/default.rs index c2b4852a4..efdb0d18f 100644 --- a/crossbeam-epoch/src/default.rs +++ b/crossbeam-epoch/src/default.rs @@ -79,7 +79,6 @@ mod tests { super::pin(); // At thread exit, `HANDLE` gets dropped first and `FOO` second. }); - }) - .unwrap(); + }); } } diff --git a/crossbeam-epoch/src/sync/list.rs b/crossbeam-epoch/src/sync/list.rs index 52ffd6fca..ee6ca84a3 100644 --- a/crossbeam-epoch/src/sync/list.rs +++ b/crossbeam-epoch/src/sync/list.rs @@ -428,8 +428,7 @@ mod tests { } }); } - }) - .unwrap(); + }); let handle = collector.register(); let guard = handle.pin(); @@ -475,8 +474,7 @@ mod tests { } }); } - }) - .unwrap(); + }); let handle = collector.register(); let guard = handle.pin(); diff --git a/crossbeam-epoch/src/sync/queue.rs b/crossbeam-epoch/src/sync/queue.rs index 950043881..e838fb5ae 100644 --- a/crossbeam-epoch/src/sync/queue.rs +++ b/crossbeam-epoch/src/sync/queue.rs @@ -353,8 +353,7 @@ mod test { for i in 0..CONC_COUNT { q.push(i) } - }) - .unwrap(); + }); } #[test] @@ -386,8 +385,7 @@ mod test { q.push(i); } }); - }) - .unwrap(); + }); } #[test] @@ -432,8 +430,7 @@ mod test { assert_eq!(vr, vr2); }); } - }) - .unwrap(); + }); } #[test] @@ -452,8 +449,7 @@ mod test { for i in 0..CONC_COUNT { q.push(i) } - }) - .unwrap(); + }); assert!(q.is_empty()); } diff --git a/crossbeam-queue/tests/array_queue.rs b/crossbeam-queue/tests/array_queue.rs index a2afc3ec8..bdec25ab3 100644 --- a/crossbeam-queue/tests/array_queue.rs +++ b/crossbeam-queue/tests/array_queue.rs @@ -120,8 +120,7 @@ fn len() { assert!(len <= CAP); } }); - }) - .unwrap(); + }); assert_eq!(q.len(), 0); } @@ -157,8 +156,7 @@ fn spsc() { } } }); - }) - .unwrap(); + }); } #[test] @@ -196,8 +194,7 @@ fn spsc_ring_buffer() { t.fetch_sub(1, Ordering::SeqCst); }); - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(Ordering::SeqCst), 1); @@ -233,8 +230,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(Ordering::SeqCst), THREADS); @@ -277,8 +273,7 @@ fn mpmc_ring_buffer() { t.fetch_sub(1, Ordering::SeqCst); }); } - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(Ordering::SeqCst), THREADS); @@ -335,8 +330,7 @@ fn drops() { } } }); - }) - .unwrap(); + }); for _ in 0..additional { q.push(DropCounter).unwrap(); @@ -375,8 +369,7 @@ fn linearizable() { } }); } - }) - .unwrap(); + }); } #[test] diff --git a/crossbeam-queue/tests/seg_queue.rs b/crossbeam-queue/tests/seg_queue.rs index 22840fe41..818aa0d08 100644 --- a/crossbeam-queue/tests/seg_queue.rs +++ b/crossbeam-queue/tests/seg_queue.rs @@ -80,8 +80,7 @@ fn spsc() { q.push(i); } }); - }) - .unwrap(); + }); } #[cfg_attr(miri, ignore)] // Miri is too slow @@ -113,8 +112,7 @@ fn mpmc() { } }); } - }) - .unwrap(); + }); for c in v { assert_eq!(c.load(Ordering::SeqCst), THREADS); @@ -167,8 +165,7 @@ fn drops() { q.push(DropCounter); } }); - }) - .unwrap(); + }); for _ in 0..additional { q.push(DropCounter); diff --git a/crossbeam-skiplist/src/lib.rs b/crossbeam-skiplist/src/lib.rs index cb5f0462d..cd057d434 100644 --- a/crossbeam-skiplist/src/lib.rs +++ b/crossbeam-skiplist/src/lib.rs @@ -32,7 +32,7 @@ //! person_ages.insert("Bryon Conroy", 65); //! person_ages.insert("Lauren Reilly", 2); //! }); -//! }).unwrap(); +//! }); //! //! assert!(person_ages.contains_key("Spike Garrett")); //! person_ages.remove("Rea Bryan"); @@ -64,7 +64,7 @@ //! // The other thread may remove the value //! // before we perform this check. //! assert!(numbers.contains(&5)); -//! }).unwrap(); +//! }); //! ``` //! //! In effect, a _single_ operation on the map, such as [`insert`], diff --git a/crossbeam-skiplist/tests/map.rs b/crossbeam-skiplist/tests/map.rs index 4ea2948f6..4891b9176 100644 --- a/crossbeam-skiplist/tests/map.rs +++ b/crossbeam-skiplist/tests/map.rs @@ -100,8 +100,7 @@ fn concurrent_insert() { barrier.wait(); set.insert(1, 1); }); - }) - .unwrap(); + }); } } @@ -120,8 +119,7 @@ fn concurrent_remove() { barrier.wait(); set.remove(&1); }); - }) - .unwrap(); + }); } } diff --git a/crossbeam-skiplist/tests/set.rs b/crossbeam-skiplist/tests/set.rs index b6987b8bb..568563eb6 100644 --- a/crossbeam-skiplist/tests/set.rs +++ b/crossbeam-skiplist/tests/set.rs @@ -97,8 +97,7 @@ fn concurrent_insert() { barrier.wait(); set.insert(1); }); - }) - .unwrap(); + }); } } @@ -117,8 +116,7 @@ fn concurrent_remove() { barrier.wait(); set.remove(&1); }); - }) - .unwrap(); + }); } } diff --git a/crossbeam-utils/benches/atomic_cell.rs b/crossbeam-utils/benches/atomic_cell.rs index 844f7c02b..9983b1c27 100644 --- a/crossbeam-utils/benches/atomic_cell.rs +++ b/crossbeam-utils/benches/atomic_cell.rs @@ -77,8 +77,7 @@ fn concurrent_load_u8(b: &mut test::Bencher) { start.wait(); exit.store(true); end.wait(); - }) - .unwrap(); + }); } #[bench] @@ -151,6 +150,5 @@ fn concurrent_load_usize(b: &mut test::Bencher) { start.wait(); exit.store(true); end.wait(); - }) - .unwrap(); + }); } diff --git a/crossbeam-utils/src/thread.rs b/crossbeam-utils/src/thread.rs index f1086d9ec..f8f281f0e 100644 --- a/crossbeam-utils/src/thread.rs +++ b/crossbeam-utils/src/thread.rs @@ -17,7 +17,7 @@ //! println!("Hello, {}!", person); //! }); //! } -//! }).unwrap(); +//! }); //! ``` //! //! # Why scoped threads? @@ -108,7 +108,7 @@ //! // Yay, this works because we're using a fresh argument `s`! :) //! s.spawn(|_| println!("nested thread")); //! }); -//! }).unwrap(); +//! }); //! ``` use std::fmt; @@ -116,15 +116,13 @@ use std::io; use std::marker::PhantomData; use std::mem; use std::panic; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use std::thread; use crate::sync::WaitGroup; use cfg_if::cfg_if; -type SharedVec = Arc>>; -type SharedOption = Arc>>; - /// Creates a new scope for spawning threads. /// /// All child threads that haven't been manually joined will be automatically joined just before @@ -144,15 +142,15 @@ type SharedOption = Arc>>; /// s.spawn(|_| { /// println!("A child thread borrowing `var`: {:?}", var); /// }); -/// }).unwrap(); +/// }); /// ``` -pub fn scope<'env, F, R>(f: F) -> thread::Result +pub fn scope<'env, F, R>(f: F) -> R where F: FnOnce(&Scope<'env>) -> R, { let wg = WaitGroup::new(); let scope = Scope::<'env> { - handles: SharedVec::default(), + num_unhandled_panicked_threads: Arc::new(AtomicUsize::new(0)), wait_group: wg.clone(), _marker: PhantomData, }; @@ -164,36 +162,29 @@ where drop(scope.wait_group); wg.wait(); - // Join all remaining spawned threads. - let panics: Vec<_> = scope - .handles - .lock() - .unwrap() - // Filter handles that haven't been joined, join them, and collect errors. - .drain(..) - .filter_map(|handle| handle.lock().unwrap().take()) - .filter_map(|handle| handle.join().err()) - .collect(); - // If `f` has panicked, resume unwinding. // If any of the child threads have panicked, return the panic errors. // Otherwise, everything is OK and return the result of `f`. match result { Err(err) => panic::resume_unwind(err), Ok(res) => { - if panics.is_empty() { - Ok(res) - } else { - Err(Box::new(panics)) + let num_unhandled_panicked_threads = + scope.num_unhandled_panicked_threads.load(Ordering::Acquire); + if num_unhandled_panicked_threads != 0 { + panic!( + "{} scoped thread(s) panicked", + num_unhandled_panicked_threads + ) } + res } } } /// A scope for spawning threads. pub struct Scope<'env> { - /// The list of the thread join handles. - handles: SharedVec>>, + /// Number of unhandled panicked threads. + num_unhandled_panicked_threads: Arc, /// Used to wait until all subscopes all dropped. wait_group: WaitGroup, @@ -241,7 +232,7 @@ impl<'env> Scope<'env> { /// // Join the thread and retrieve its result. /// let res = handle.join().unwrap(); /// assert_eq!(res, 42); - /// }).unwrap(); + /// }); /// ``` pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T> where @@ -265,7 +256,7 @@ impl<'env> Scope<'env> { /// s.builder() /// .spawn(|_| println!("A child thread is running")) /// .unwrap(); - /// }).unwrap(); + /// }); /// ``` pub fn builder<'scope>(&'scope self) -> ScopedThreadBuilder<'scope, 'env> { ScopedThreadBuilder { @@ -304,7 +295,7 @@ impl fmt::Debug for Scope<'_> { /// s.builder() /// .spawn(|_| println!("Running a child thread")) /// .unwrap(); -/// }).unwrap(); +/// }); /// ``` /// /// [`name`]: ScopedThreadBuilder::name @@ -337,7 +328,7 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { /// .name("my thread".to_string()) /// .spawn(|_| assert_eq!(current().name(), Some("my thread"))) /// .unwrap(); - /// }).unwrap(); + /// }); /// ``` /// /// [naming-threads]: std::thread#naming-threads @@ -362,7 +353,7 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { /// .stack_size(32 * 1024) /// .spawn(|_| println!("Running a child thread")) /// .unwrap(); - /// }).unwrap(); + /// }); /// ``` /// /// [stack-size]: std::thread#stack-size @@ -406,7 +397,7 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { /// // Join the thread and retrieve its result. /// let res = handle.join().unwrap(); /// assert_eq!(res, 42); - /// }).unwrap(); + /// }); /// ``` pub fn spawn(self, f: F) -> io::Result> where @@ -415,7 +406,10 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { T: Send + 'env, { // The result of `f` will be stored here. - let result = SharedOption::default(); + let result = Arc::new(Mutex::new(ResultState::None)); + + let wait_group = self.scope.wait_group.clone(); + let num_unhandled_panicked_threads = Arc::clone(&self.scope.num_unhandled_panicked_threads); // Spawn the thread and grab its join handle and thread handle. let (handle, thread) = { @@ -423,7 +417,7 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { // A clone of the scope that will be moved into the new thread. let scope = Scope::<'env> { - handles: Arc::clone(&self.scope.handles), + num_unhandled_panicked_threads: Arc::clone(&num_unhandled_panicked_threads), wait_group: self.scope.wait_group.clone(), _marker: PhantomData, }; @@ -431,14 +425,35 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { // Spawn the thread. let handle = { let closure = move || { + struct IncrementOnPanic<'env>(Scope<'env>); + impl Drop for IncrementOnPanic<'_> { + fn drop(&mut self) { + if thread::panicking() { + // Always increment the counter here. If panic is handled + // by `.join()`, the counter is decremented later. + self.0 + .num_unhandled_panicked_threads + .fetch_add(1, Ordering::Release); + } + } + } + // Make sure the scope is inside the closure with the proper `'env` lifetime. let scope: Scope<'env> = scope; + let scope = IncrementOnPanic(scope); // Run the closure. - let res = f(&scope); + let res = f(&scope.0); - // Store the result if the closure didn't panic. - *result.lock().unwrap() = Some(res); + match &mut *result.lock().unwrap() { + // If the thread is detached, the result must be dropped + // before the WaitGroup is dropped. + ResultState::ShouldDrop => drop(res), + // Store the result if the closure didn't panic. + result => *result = ResultState::Some(res), + } + + drop(scope); }; // Allocate `closure` on the heap and erase the `'env` bound. @@ -451,22 +466,35 @@ impl<'scope, 'env> ScopedThreadBuilder<'scope, 'env> { }; let thread = handle.thread().clone(); - let handle = Arc::new(Mutex::new(Some(handle))); (handle, thread) }; - // Add the handle to the shared list of join handles. - self.scope.handles.lock().unwrap().push(Arc::clone(&handle)); - Ok(ScopedJoinHandle { - handle, + handle: Some(handle), + num_unhandled_panicked_threads, result, thread, + _wait_group: wait_group, _marker: PhantomData, }) } } +enum ResultState { + None, + Some(T), + ShouldDrop, +} + +impl ResultState { + fn take(&mut self) -> Option { + match mem::replace(self, ResultState::None) { + ResultState::Some(v) => Some(v), + _ => None, + } + } +} + unsafe impl Send for ScopedJoinHandle<'_, T> {} unsafe impl Sync for ScopedJoinHandle<'_, T> {} @@ -476,14 +504,19 @@ unsafe impl Sync for ScopedJoinHandle<'_, T> {} /// [`ScopedThreadBuilder::spawn`] method. pub struct ScopedJoinHandle<'scope, T> { /// A join handle to the spawned thread. - handle: SharedOption>, + handle: Option>, + + /// Number of unhandled panicked threads. + num_unhandled_panicked_threads: Arc, /// Holds the result of the inner closure. - result: SharedOption, + result: Arc>>, /// A handle to the the spawned thread. thread: thread::Thread, + _wait_group: WaitGroup, + /// Borrows the parent scope with lifetime `'scope`. _marker: PhantomData<&'scope ()>, } @@ -515,17 +548,23 @@ impl ScopedJoinHandle<'_, T> { /// // Join the second thread and verify that it panicked. /// let res = handle2.join(); /// assert!(res.is_err()); - /// }).unwrap(); + /// }); /// ``` - pub fn join(self) -> thread::Result { + pub fn join(mut self) -> thread::Result { // Take out the handle. The handle will surely be available because the root scope waits // for nested scopes before joining remaining threads. - let handle = self.handle.lock().unwrap().take().unwrap(); + let handle = self.handle.take().unwrap(); // Join the thread and then take the result out of its inner closure. - handle - .join() - .map(|()| self.result.lock().unwrap().take().unwrap()) + match handle.join() { + Ok(()) => Ok(self.result.lock().unwrap().take().unwrap()), + Err(e) => { + // Decrement the counter as we handled a panic from this handle. + self.num_unhandled_panicked_threads + .fetch_sub(1, Ordering::Release); + Err(e) + } + } } /// Returns a handle to the underlying thread. @@ -538,23 +577,32 @@ impl ScopedJoinHandle<'_, T> { /// thread::scope(|s| { /// let handle = s.spawn(|_| println!("A child thread is running")); /// println!("The child thread ID: {:?}", handle.thread().id()); - /// }).unwrap(); + /// }); /// ``` pub fn thread(&self) -> &thread::Thread { &self.thread } } +impl Drop for ScopedJoinHandle<'_, T> { + fn drop(&mut self) { + *self + .result + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) = ResultState::ShouldDrop; + } +} + cfg_if! { if #[cfg(unix)] { use std::os::unix::thread::{JoinHandleExt, RawPthread}; + // TODO: Use own unix::JoinHandleExt trait https://github.com/crossbeam-rs/crossbeam/issues/651 impl JoinHandleExt for ScopedJoinHandle<'_, T> { fn as_pthread_t(&self) -> RawPthread { // Borrow the handle. The handle will surely be available because the root scope waits // for nested scopes before joining remaining threads. - let handle = self.handle.lock().unwrap(); - handle.as_ref().unwrap().as_pthread_t() + self.handle.as_ref().unwrap().as_pthread_t() } fn into_pthread_t(self) -> RawPthread { self.as_pthread_t() @@ -567,8 +615,7 @@ cfg_if! { fn as_raw_handle(&self) -> RawHandle { // Borrow the handle. The handle will surely be available because the root scope waits // for nested scopes before joining remaining threads. - let handle = self.handle.lock().unwrap(); - handle.as_ref().unwrap().as_raw_handle() + self.handle.as_ref().unwrap().as_raw_handle() } } diff --git a/crossbeam-utils/tests/parker.rs b/crossbeam-utils/tests/parker.rs index 2bf9c37d4..718898319 100644 --- a/crossbeam-utils/tests/parker.rs +++ b/crossbeam-utils/tests/parker.rs @@ -35,7 +35,6 @@ fn park_timeout_unpark_called_other_thread() { }); p.park_timeout(Duration::from_millis(u32::MAX as u64)) - }) - .unwrap(); + }); } } diff --git a/crossbeam-utils/tests/thread.rs b/crossbeam-utils/tests/thread.rs index 0dfad90bd..f2ca6051d 100644 --- a/crossbeam-utils/tests/thread.rs +++ b/crossbeam-utils/tests/thread.rs @@ -1,5 +1,4 @@ -use std::any::Any; -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::thread::sleep; use std::time::Duration; @@ -21,8 +20,7 @@ fn join() { panic!("\"My honey is running out!\", said Pooh."); }); assert!(panic_handle.join().is_err()); - }) - .unwrap(); + }); // There should be sufficient synchronization. assert_eq!(1, counter.load(Ordering::Relaxed)); @@ -37,8 +35,7 @@ fn counter() { counter.fetch_add(1, Ordering::Relaxed); }); } - }) - .unwrap(); + }); assert_eq!(THREADS, counter.load(Ordering::Relaxed)); } @@ -57,8 +54,7 @@ fn counter_builder() { }) .unwrap(); } - }) - .unwrap(); + }); assert_eq!(THREADS, counter.load(Ordering::Relaxed)); } @@ -66,26 +62,29 @@ fn counter_builder() { #[test] fn counter_panic() { let counter = AtomicUsize::new(0); - let result = thread::scope(|scope| { - scope.spawn(|_| { - panic!("\"My honey is running out!\", said Pooh."); - }); - sleep(Duration::from_millis(100)); - - for _ in 0..THREADS { + let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + thread::scope(|scope| { scope.spawn(|_| { - counter.fetch_add(1, Ordering::Relaxed); + panic!("\"My honey is running out!\", said Pooh."); }); - } - }); + sleep(Duration::from_millis(100)); + + for _ in 0..THREADS { + scope.spawn(|_| { + counter.fetch_add(1, Ordering::Relaxed); + }); + } + }); + })); assert_eq!(THREADS, counter.load(Ordering::Relaxed)); assert!(result.is_err()); } #[test] +#[should_panic = "2 scoped thread(s) panicked"] fn panic_twice() { - let result = thread::scope(|scope| { + thread::scope(|scope| { scope.spawn(|_| { sleep(Duration::from_millis(500)); panic!("thread #1"); @@ -94,41 +93,16 @@ fn panic_twice() { panic!("thread #2"); }); }); - - let err = result.unwrap_err(); - let vec = err - .downcast_ref::>>() - .unwrap(); - assert_eq!(2, vec.len()); - - let first = vec[0].downcast_ref::<&str>().unwrap(); - let second = vec[1].downcast_ref::<&str>().unwrap(); - assert_eq!("thread #1", *first); - assert_eq!("thread #2", *second) } #[test] +#[should_panic = "3 scoped thread(s) panicked"] fn panic_many() { - let result = thread::scope(|scope| { + thread::scope(|scope| { scope.spawn(|_| panic!("deliberate panic #1")); scope.spawn(|_| panic!("deliberate panic #2")); scope.spawn(|_| panic!("deliberate panic #3")); }); - - let err = result.unwrap_err(); - let vec = err - .downcast_ref::>>() - .unwrap(); - assert_eq!(3, vec.len()); - - for panic in vec.iter() { - let panic = panic.downcast_ref::<&str>().unwrap(); - assert!( - *panic == "deliberate panic #1" - || *panic == "deliberate panic #2" - || *panic == "deliberate panic #3" - ); - } } #[test] @@ -159,8 +133,7 @@ fn nesting() { wrapper.recurse(scope, 5); }); }); - }) - .unwrap(); + }); } #[test] @@ -174,13 +147,12 @@ fn join_nested() { }); sleep(Duration::from_millis(100)); - }) - .unwrap(); + }); } #[test] fn scope_returns_ok() { - let result = thread::scope(|scope| scope.spawn(|_| 1234).join().unwrap()).unwrap(); + let result = thread::scope(|scope| scope.spawn(|_| 1234).join().unwrap()); assert_eq!(result, 1234); } @@ -195,8 +167,7 @@ fn as_pthread_t() { }); let _pthread_t = handle.as_pthread_t(); handle.join().unwrap(); - }) - .unwrap(); + }); } #[cfg(windows)] @@ -210,6 +181,23 @@ fn as_raw_handle() { }); let _raw_handle = handle.as_raw_handle(); handle.join().unwrap(); - }) - .unwrap(); + }); +} + +// https://github.com/rust-lang/rust/pull/94644 +// https://github.com/crossbeam-rs/crossbeam/pull/844#issuecomment-1143288972 +#[test] +fn test_scoped_threads_drop_result_before_join() { + let actually_finished = &AtomicBool::new(false); + struct X<'a>(&'a AtomicBool); + impl Drop for X<'_> { + fn drop(&mut self) { + std::thread::sleep(Duration::from_millis(100)); + self.0.store(true, Ordering::Relaxed); + } + } + thread::scope(|s| { + s.spawn(move |_| X(actually_finished)); + }); + assert!(actually_finished.load(Ordering::Relaxed)); } diff --git a/tests/subcrates.rs b/tests/subcrates.rs index 21b99fb0e..b27cbf3f7 100644 --- a/tests/subcrates.rs +++ b/tests/subcrates.rs @@ -37,11 +37,9 @@ fn utils() { crossbeam::scope(|scope| { scope.spawn(|_| ()); - }) - .unwrap(); + }); crossbeam::thread::scope(|scope| { scope.spawn(|_| ()); - }) - .unwrap(); + }); }