diff --git a/tokio/src/loom/std/atomic_u16.rs b/tokio/src/loom/std/atomic_u16.rs index dfc31f642a6..32ae349c33f 100644 --- a/tokio/src/loom/std/atomic_u16.rs +++ b/tokio/src/loom/std/atomic_u16.rs @@ -1,6 +1,7 @@ use std::cell::UnsafeCell; use std::fmt; use std::ops::Deref; +use std::panic; /// `AtomicU16` providing an additional `unsync_load` function. pub(crate) struct AtomicU16 { @@ -9,6 +10,8 @@ pub(crate) struct AtomicU16 { unsafe impl Send for AtomicU16 {} unsafe impl Sync for AtomicU16 {} +impl panic::RefUnwindSafe for AtomicU16 {} +impl panic::UnwindSafe for AtomicU16 {} impl AtomicU16 { pub(crate) const fn new(val: u16) -> AtomicU16 { diff --git a/tokio/src/loom/std/atomic_u32.rs b/tokio/src/loom/std/atomic_u32.rs index 94400176911..c34ca940f8a 100644 --- a/tokio/src/loom/std/atomic_u32.rs +++ b/tokio/src/loom/std/atomic_u32.rs @@ -1,6 +1,7 @@ use std::cell::UnsafeCell; use std::fmt; use std::ops::Deref; +use std::panic; /// `AtomicU32` providing an additional `unsync_load` function. pub(crate) struct AtomicU32 { @@ -9,6 +10,8 @@ pub(crate) struct AtomicU32 { unsafe impl Send for AtomicU32 {} unsafe impl Sync for AtomicU32 {} +impl panic::RefUnwindSafe for AtomicU32 {} +impl panic::UnwindSafe for AtomicU32 {} impl AtomicU32 { pub(crate) const fn new(val: u32) -> AtomicU32 { diff --git a/tokio/src/loom/std/atomic_usize.rs b/tokio/src/loom/std/atomic_usize.rs index 64605c76dd0..f88cc4bf727 100644 --- a/tokio/src/loom/std/atomic_usize.rs +++ b/tokio/src/loom/std/atomic_usize.rs @@ -1,6 +1,7 @@ use std::cell::UnsafeCell; use std::fmt; use std::ops; +use std::panic; /// `AtomicUsize` providing an additional `unsync_load` function. pub(crate) struct AtomicUsize { @@ -9,6 +10,8 @@ pub(crate) struct AtomicUsize { unsafe impl Send for AtomicUsize {} unsafe impl Sync for AtomicUsize {} +impl panic::RefUnwindSafe for AtomicUsize {} +impl panic::UnwindSafe for AtomicUsize {} impl AtomicUsize { pub(crate) const fn new(val: usize) -> AtomicUsize { diff --git a/tokio/src/sync/mpsc/chan.rs b/tokio/src/sync/mpsc/chan.rs index 4006aa2b746..1edd2a755ae 100644 --- a/tokio/src/sync/mpsc/chan.rs +++ b/tokio/src/sync/mpsc/chan.rs @@ -9,6 +9,7 @@ use crate::sync::notify::Notify; use crate::util::cacheline::CachePadded; use std::fmt; +use std::panic; use std::process; use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release}; use std::task::Poll::{Pending, Ready}; @@ -108,6 +109,8 @@ impl fmt::Debug for RxFields { unsafe impl Send for Chan {} unsafe impl Sync for Chan {} +impl panic::RefUnwindSafe for Chan {} +impl panic::UnwindSafe for Chan {} pub(crate) fn channel(semaphore: S) -> (Tx, Rx) { let (tx, rx) = list::channel(); diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index 52b3835b753..0f578422bc0 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -413,6 +413,12 @@ assert_value!(tokio::sync::mpsc::UnboundedReceiver: Send & Sync & Unpin); assert_value!(tokio::sync::mpsc::UnboundedSender: !Send & !Sync & Unpin); assert_value!(tokio::sync::mpsc::UnboundedSender: Send & Sync & Unpin); assert_value!(tokio::sync::mpsc::UnboundedSender: Send & Sync & Unpin); +assert_value!(tokio::sync::mpsc::WeakSender: !Send & !Sync & Unpin); +assert_value!(tokio::sync::mpsc::WeakSender: Send & Sync & Unpin); +assert_value!(tokio::sync::mpsc::WeakSender: Send & Sync & Unpin); +assert_value!(tokio::sync::mpsc::WeakUnboundedSender: !Send & !Sync & Unpin); +assert_value!(tokio::sync::mpsc::WeakUnboundedSender: Send & Sync & Unpin); +assert_value!(tokio::sync::mpsc::WeakUnboundedSender: Send & Sync & Unpin); assert_value!(tokio::sync::mpsc::error::SendError: !Send & !Sync & Unpin); assert_value!(tokio::sync::mpsc::error::SendError: Send & !Sync & Unpin); assert_value!(tokio::sync::mpsc::error::SendError: Send & Sync & Unpin); diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index cc88fa79972..3d91c5cf3e8 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -11,6 +11,7 @@ use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; use tokio::test as maybe_tokio_test; use std::fmt; +use std::panic; use std::sync::Arc; use tokio::sync::mpsc; use tokio::sync::mpsc::error::{TryRecvError, TrySendError}; @@ -22,9 +23,28 @@ mod support { } #[allow(unused)] -trait AssertSend: Send {} -impl AssertSend for mpsc::Sender {} -impl AssertSend for mpsc::Receiver {} +trait AssertRefUnwindSafe: panic::RefUnwindSafe {} +impl AssertRefUnwindSafe for mpsc::OwnedPermit {} +impl<'a, T> AssertRefUnwindSafe for mpsc::Permit<'a, T> {} +impl<'a, T> AssertRefUnwindSafe for mpsc::PermitIterator<'a, T> {} +impl AssertRefUnwindSafe for mpsc::Receiver {} +impl AssertRefUnwindSafe for mpsc::Sender {} +impl AssertRefUnwindSafe for mpsc::UnboundedReceiver {} +impl AssertRefUnwindSafe for mpsc::UnboundedSender {} +impl AssertRefUnwindSafe for mpsc::WeakSender {} +impl AssertRefUnwindSafe for mpsc::WeakUnboundedSender {} + +#[allow(unused)] +trait AssertUnwindSafe: panic::UnwindSafe {} +impl AssertUnwindSafe for mpsc::OwnedPermit {} +impl<'a, T> AssertUnwindSafe for mpsc::Permit<'a, T> {} +impl<'a, T> AssertUnwindSafe for mpsc::PermitIterator<'a, T> {} +impl AssertUnwindSafe for mpsc::Receiver {} +impl AssertUnwindSafe for mpsc::Sender {} +impl AssertUnwindSafe for mpsc::UnboundedReceiver {} +impl AssertUnwindSafe for mpsc::UnboundedSender {} +impl AssertUnwindSafe for mpsc::WeakSender {} +impl AssertUnwindSafe for mpsc::WeakUnboundedSender {} #[maybe_tokio_test] async fn send_recv_with_buffer() {