From 0d476b4975255ddcadb1bc06df82967b49a062eb Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 13 Oct 2022 15:47:36 -0700 Subject: [PATCH] rt: remove a conditional compilation clause The `LocalSet` implementation includes a conditional compilation clause that removes the `const` statement from the `thread_local` definition. However, there already is an internal macro that does this: `tokio_thread_local`. This patch removes the conditional compilation in favor of using the `tokio_thread_local` macro. This also fixes a conditional compilation issue with an internal utility (`RcCell`). --- tokio/src/task/local.rs | 7 ------- tokio/src/util/rc_cell.rs | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 22ce14aebaa..4a2209cd2e8 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -272,13 +272,6 @@ pin_project! { } } -#[cfg(any(loom, tokio_no_const_thread_local))] -tokio_thread_local!(static CURRENT: LocalData = LocalData { - thread_id: Cell::new(None), - ctx: RcCell::new(), -}); - -#[cfg(not(any(loom, tokio_no_const_thread_local)))] tokio_thread_local!(static CURRENT: LocalData = const { LocalData { thread_id: Cell::new(None), ctx: RcCell::new(), diff --git a/tokio/src/util/rc_cell.rs b/tokio/src/util/rc_cell.rs index 97c02053c59..44724926848 100644 --- a/tokio/src/util/rc_cell.rs +++ b/tokio/src/util/rc_cell.rs @@ -9,7 +9,7 @@ pub(crate) struct RcCell { } impl RcCell { - #[cfg(not(loom))] + #[cfg(not(all(loom, test)))] pub(crate) const fn new() -> Self { Self { inner: UnsafeCell::new(None), @@ -17,7 +17,7 @@ impl RcCell { } // The UnsafeCell in loom does not have a const `new` fn. - #[cfg(loom)] + #[cfg(all(loom, test))] pub(crate) fn new() -> Self { Self { inner: UnsafeCell::new(None),