From ed8589e5477de4a0419e2d0d0eb299680511d22c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 4 Jun 2026 09:46:09 +0200 Subject: [PATCH] std tests: avoid duplicating thread-local machinery --- library/std/src/lib.rs | 1 + library/std/src/thread/mod.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 09d81f11e0a45..9f5200dab80df 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -383,6 +383,7 @@ #![feature(str_internals)] #![feature(sync_unsafe_cell)] #![feature(temporary_niche_types)] +#![feature(thread_local_internals)] #![feature(ub_checks)] #![feature(uint_carryless_mul)] #![feature(used_with_arg)] diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 00aeb70e6e076..6e052a34069fe 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -199,6 +199,7 @@ pub use id::ThreadId; pub use join_handle::JoinHandle; pub(crate) use lifecycle::ThreadInit; #[stable(feature = "rust1", since = "1.0.0")] +#[cfg(not(test))] // we use the realstd types instead, see below pub use local::{AccessError, LocalKey}; #[stable(feature = "scoped_threads", since = "1.63.0")] pub use scoped::{Scope, ScopedJoinHandle, scope}; @@ -210,10 +211,18 @@ pub use thread::Thread; // Implementation details used by the thread_local!{} macro. #[doc(hidden)] #[unstable(feature = "thread_local_internals", issue = "none")] +#[cfg(not(test))] // we use the realstd types instead, see below pub mod local_impl { pub use super::local::thread_local_process_attrs; pub use crate::sys::thread_local::*; } +// Under cfg(test), avoid having two instances of the thread-local machinery. +// Things too easily get mixed up and then we end up with memory leaks because we're not calling +// all the right dtors. +#[cfg(test)] +pub use realstd::thread::local_impl; +#[cfg(test)] +pub use realstd::thread::{AccessError, LocalKey}; /// A specialized [`Result`] type for threads. ///