Skip to content

Commit d701e06

Browse files
Darksonnojeda
authored andcommitted
rust: sync: reword the Arc safety comment for Sync
The safety comment on `impl Sync for Arc` references the Send safety comment. This commit avoids that in case the two comments drift apart in the future. Suggested-by: Andreas Hindborg <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent f8110cd commit d701e06

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rust/kernel/sync/arc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> core::ops::DispatchFromDyn<Arc<U>> for Ar
150150
// mutable reference when the reference count reaches zero and `T` is dropped.
151151
unsafe impl<T: ?Sized + Sync + Send> Send for Arc<T> {}
152152

153-
// SAFETY: It is safe to send `&Arc<T>` to another thread when the underlying `T` is `Sync` for the
154-
// same reason as above. `T` needs to be `Send` as well because a thread can clone an `&Arc<T>`
155-
// into an `Arc<T>`, which may lead to `T` being accessed by the same reasoning as above.
153+
// SAFETY: It is safe to send `&Arc<T>` to another thread when the underlying `T` is `Sync`
154+
// because it effectively means sharing `&T` (which is safe because `T` is `Sync`); additionally,
155+
// it needs `T` to be `Send` because any thread that has a `&Arc<T>` may clone it and get an
156+
// `Arc<T>` on that thread, so the thread may ultimately access `T` using a mutable reference when
157+
// the reference count reaches zero and `T` is dropped.
156158
unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
157159

158160
impl<T> Arc<T> {

0 commit comments

Comments
 (0)