about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorAskar Safin <safinaskar@mail.ru>2025-03-04 15:32:55 +0300
committerAskar Safin <safinaskar@mail.ru>2025-03-04 15:32:55 +0300
commitc6c4ea40dc645239ebcb0535be6b96a29983fd5b (patch)
tree2d7021e18b95532416d7565ec6af27f9d851bed1 /compiler/rustc_data_structures/src
parentfd17deacce374a4185c882795be162e17b557050 (diff)
downloadrust-c6c4ea40dc645239ebcb0535be6b96a29983fd5b.tar.gz
rust-c6c4ea40dc645239ebcb0535be6b96a29983fd5b.zip
Revert "compiler/rustc_data_structures/src/sync/worker_local.rs: delete "unsafe impl Sync""
This reverts commit 02406903b0c26440428580a4bbaf30da973c5b23.
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 }
     }
 }