diff --git a/tokio/src/runtime/context.rs b/tokio/src/runtime/context.rs index c0d3be3257a..388171d0161 100644 --- a/tokio/src/runtime/context.rs +++ b/tokio/src/runtime/context.rs @@ -159,6 +159,9 @@ cfg_rt! { pub(crate) struct SetCurrentGuard { old_handle: Option, old_seed: RngSeed, + // Should not be `Send` since it must be *dropped* on the same thread as + // created, but there is no issue with sync access. + _p: PhantomData, } /// Guard tracking that a caller has entered a runtime context. @@ -308,6 +311,7 @@ cfg_rt! { SetCurrentGuard { old_handle, old_seed, + _p: PhantomData, } } } diff --git a/tokio/src/util/markers.rs b/tokio/src/util/markers.rs new file mode 100644 index 00000000000..1da09da94af --- /dev/null +++ b/tokio/src/util/markers.rs @@ -0,0 +1,4 @@ +/// Marker for types that are `Sync` but not `Send` +pub(crate) struct SyncNotSend(*mut ()); + +unsafe impl Sync for SyncNotSend {} diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs index b1afc5716b9..6a7d4b1037c 100644 --- a/tokio/src/util/mod.rs +++ b/tokio/src/util/mod.rs @@ -79,3 +79,5 @@ pub(crate) mod error; #[cfg(feature = "io-util")] pub(crate) mod memchr; + +pub(crate) mod markers; diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index 0c2c34a0796..32c03a54be2 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -532,7 +532,7 @@ async_assert_fn!(tokio::task::unconstrained(BoxFutureSend<()>): Send & !Sync & U async_assert_fn!(tokio::task::unconstrained(BoxFutureSync<()>): Send & Sync & Unpin); assert_value!(tokio::runtime::Builder: Send & Sync & Unpin); -assert_value!(tokio::runtime::EnterGuard<'_>: Send & Sync & Unpin); +assert_value!(tokio::runtime::EnterGuard<'_>: !Send & Sync & Unpin); assert_value!(tokio::runtime::Handle: Send & Sync & Unpin); assert_value!(tokio::runtime::Runtime: Send & Sync & Unpin);