Skip to content

Commit c234b5f

Browse files
committed
Add bounds for WorkerLocal's Send and Sync
1 parent ae7bbbd commit c234b5f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

rayon-core/src/worker_local.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ pub struct WorkerLocal<T> {
1515
registry: Arc<Registry>,
1616
}
1717

18-
unsafe impl<T> Send for WorkerLocal<T> {}
19-
unsafe impl<T> Sync for WorkerLocal<T> {}
18+
/// We prevent concurrent access to the underlying value in the
19+
/// Deref impl, thus any values safe to send across threads can
20+
/// be used with WorkerLocal.
21+
unsafe impl<T: Send> Sync for WorkerLocal<T> {}
2022

2123
impl<T> WorkerLocal<T> {
2224
/// Creates a new worker local where the `initial` closure computes the
@@ -60,7 +62,9 @@ impl<T> WorkerLocal<Vec<T>> {
6062

6163
impl<T: fmt::Debug> fmt::Debug for WorkerLocal<T> {
6264
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63-
fmt::Debug::fmt(&self.locals, f)
65+
f.debug_struct("WorkerLocal")
66+
.field("registry", &self.registry.id())
67+
.finish()
6468
}
6569
}
6670

0 commit comments

Comments
 (0)