about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-05 06:59:11 +0000
committerbors <bors@rust-lang.org>2025-03-05 06:59:11 +0000
commit4559163ccb500affc424fb9228dae5003672ffc7 (patch)
tree9516de75915b28be6eb85407b0e3dc8b775ebf66 /compiler/rustc_data_structures/src
parentac951d379913c667a1fb73a0830e81d65d2007cf (diff)
parent3065925c7e7bd2c46f80091f1420eeeadbb8c99b (diff)
downloadrust-4559163ccb500affc424fb9228dae5003672ffc7.tar.gz
rust-4559163ccb500affc424fb9228dae5003672ffc7.zip
Auto merge of #138031 - workingjubilee:rollup-5bsotpz, r=workingjubilee
Rollup of 15 pull requests

Successful merges:

 - #137829 (Stabilize [T]::split_off... methods)
 - #137850 (Stabilize `box_uninit_write`)
 - #137912 (Do not recover missing lifetime with random in-scope lifetime)
 - #137913 (Allow struct field default values to reference struct's generics)
 - #137923 (Simplify `<Postorder as Iterator>::size_hint`)
 - #137949 (Update MSVC INSTALL.md instructions to recommend VS 2022 + recent Windows 10/11 SDK)
 - #137963 (Add ``dyn`` keyword to `E0373` examples)
 - #137975 (Remove unused `PpMode::needs_hir`)
 - #137981 (rustdoc search: increase strictness of typechecking)
 - #137986 (Fix some typos)
 - #137991 (Add `avr-none` to SUMMARY.md and platform-support.md)
 - #137993 (Remove obsolete comment from DeduceReadOnly)
 - #137996 (Revert "compiler/rustc_data_structures/src/sync/worker_local.rs: delete "unsafe impl Sync"")
 - #138019 (Pretty-print `#[deprecated]` attribute in HIR.)
 - #138026 (Make CrateItem::body() function return an option)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/sync/worker_local.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/rustc_data_structures/src/sync/worker_local.rs b/compiler/rustc_data_structures/src/sync/worker_local.rs
index 402ec9827bb..d75af009850 100644
--- a/compiler/rustc_data_structures/src/sync/worker_local.rs
+++ b/compiler/rustc_data_structures/src/sync/worker_local.rs
@@ -106,6 +106,12 @@ pub struct WorkerLocal<T> {
     registry: Registry,
 }
 
+// This is safe because the `deref` call will return a reference to a `T` unique to each thread
+// or it will panic for threads without an associated local. So there isn't a need for `T` to do
+// it's own synchronization. The `verify` method on `RegistryId` has an issue where the id
+// can be reused, but `WorkerLocal` has a reference to `Registry` which will prevent any reuse.
+unsafe impl<T: Send> Sync for WorkerLocal<T> {}
+
 impl<T> WorkerLocal<T> {
     /// Creates a new worker local where the `initial` closure computes the
     /// value this worker local should take for each thread in the registry.
@@ -132,11 +138,6 @@ impl<T> Deref for WorkerLocal<T> {
     fn deref(&self) -> &T {
         // This is safe because `verify` will only return values less than
         // `self.registry.thread_limit` which is the size of the `self.locals` array.
-
-        // The `deref` call will return a reference to a `T` unique to each thread
-        // or it will panic for threads without an associated local. So there isn't a need for `T` to do
-        // it's own synchronization. The `verify` method on `RegistryId` has an issue where the id
-        // can be reused, but `WorkerLocal` has a reference to `Registry` which will prevent any reuse.
         unsafe { &self.locals.get_unchecked(self.registry.id().verify()).0 }
     }
 }