Skip to content

Commit 7bb7d9e

Browse files
authored
Rollup merge of rust-lang#102783 - RalfJung:tls, r=thomcc
sync thread_local key conditions exactly with what the macro uses This makes the `cfg` in `mod.rs` syntactically the same as those in `local.rs`. I don't think this should actually change anything, but seems better to be consistent? I looked into this due to rust-lang#102549, but this PR would make it *less* likely that `__OsLocalKeyInner` is going to get provided, so this cannot help with that issue. r? `@thomcc`
2 parents 8a2123a + 0910bd0 commit 7bb7d9e

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

library/std/src/thread/mod.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,49 @@ pub use scoped::{scope, Scope, ScopedJoinHandle};
192192
#[stable(feature = "rust1", since = "1.0.0")]
193193
pub use self::local::{AccessError, LocalKey};
194194

195-
// Select the type used by the thread_local! macro to access TLS keys. There
196-
// are three types: "static", "fast", "OS". The "OS" thread local key
195+
// Provide the type used by the thread_local! macro to access TLS keys. This
196+
// needs to be kept in sync with the macro itself (in `local.rs`).
197+
// There are three types: "static", "fast", "OS". The "OS" thread local key
197198
// type is accessed via platform-specific API calls and is slow, while the "fast"
198199
// key type is accessed via code generated via LLVM, where TLS keys are set up
199200
// by the elf linker. "static" is for single-threaded platforms where a global
200201
// static is sufficient.
201202

202203
#[unstable(feature = "libstd_thread_internals", issue = "none")]
203-
#[cfg(target_thread_local)]
204204
#[cfg(not(test))]
205+
#[cfg(all(
206+
target_thread_local,
207+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
208+
))]
205209
#[doc(hidden)]
206210
pub use self::local::fast::Key as __FastLocalKeyInner;
211+
212+
// when building for tests, use real std's type
207213
#[unstable(feature = "libstd_thread_internals", issue = "none")]
208-
#[cfg(target_thread_local)]
209-
#[cfg(test)] // when building for tests, use real std's key
214+
#[cfg(test)]
215+
#[cfg(all(
216+
target_thread_local,
217+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
218+
))]
210219
pub use realstd::thread::__FastLocalKeyInner;
211220

221+
// but import the local one anyway to silence 'unused' warnings
212222
#[unstable(feature = "libstd_thread_internals", issue = "none")]
213-
#[cfg(target_thread_local)]
214223
#[cfg(test)]
215-
pub use self::local::fast::Key as __FastLocalKeyInnerUnused; // we import this anyway to silence 'unused' warnings
224+
#[cfg(all(
225+
target_thread_local,
226+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
227+
))]
228+
pub use self::local::fast::Key as __FastLocalKeyInnerUnused;
216229

217230
#[unstable(feature = "libstd_thread_internals", issue = "none")]
231+
#[cfg(all(
232+
not(target_thread_local),
233+
not(all(target_family = "wasm", not(target_feature = "atomics"))),
234+
))]
218235
#[doc(hidden)]
219-
#[cfg(not(target_thread_local))]
220236
pub use self::local::os::Key as __OsLocalKeyInner;
237+
221238
#[unstable(feature = "libstd_thread_internals", issue = "none")]
222239
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
223240
#[doc(hidden)]

0 commit comments

Comments
 (0)