diff --git a/objc_id/src/id.rs b/objc_id/src/id.rs index a7bf2e730..29c4bd67a 100644 --- a/objc_id/src/id.rs +++ b/objc_id/src/id.rs @@ -104,11 +104,30 @@ where } } -unsafe impl Sync for Id where T: Sync {} +/// The `Send` implementation requires `T: Sync` because `Id` give +/// access to `&T`. +/// +/// Additiontally, it requires `T: Send` because if `T: !Send`, you could +/// clone a `Id`, send it to another thread, and drop the clone +/// last, making `dealloc` get called on the other thread, and violate +/// `T: !Send`. +unsafe impl Send for Id {} + +/// The `Sync` implementation requires `T: Sync` because `&Id` give +/// access to `&T`. +/// +/// Additiontally, it requires `T: Send`, because if `T: !Send`, you could +/// clone a `&Id` from another thread, and drop the clone last, +/// making `dealloc` get called on the other thread, and violate `T: !Send`. +unsafe impl Sync for Id {} -unsafe impl Send for Id where T: Send {} +/// `Id` are `Send` if `T` is `Send` because they give the same +/// access as having a T directly. +unsafe impl Send for Id {} -unsafe impl Send for Id where T: Sync {} +/// `Id` are `Sync` if `T` is `Sync` because they give the same +/// access as having a `T` directly. +unsafe impl Sync for Id {} impl Deref for Id { type Target = T; @@ -196,9 +215,11 @@ where } } -unsafe impl Sync for WeakId where T: Sync {} +/// This implementation follows the same reasoning as `Id`. +unsafe impl Sync for WeakId {} -unsafe impl Send for WeakId where T: Sync {} +/// This implementation follows the same reasoning as `Id`. +unsafe impl Send for WeakId {} #[cfg(test)] mod tests {