diff --git a/block-sys/src/lib.rs b/block-sys/src/lib.rs index b989303ea..9fb38f84d 100644 --- a/block-sys/src/lib.rs +++ b/block-sys/src/lib.rs @@ -35,7 +35,7 @@ pub struct Class { _priv: [u8; 0], /// See objc_sys::OpaqueData - _opaque: PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>, + _opaque: UnsafeCell, PhantomPinned)>>, } /// Block descriptor flags. diff --git a/objc-sys/src/lib.rs b/objc-sys/src/lib.rs index 5e733ec5a..12f0f5add 100644 --- a/objc-sys/src/lib.rs +++ b/objc-sys/src/lib.rs @@ -130,7 +130,7 @@ pub use various::*; /// (It's also less of a breaking change on our part if we re-add these). /// /// TODO: Replace this with `extern type` to also mark it as `!Sized`. -type OpaqueData = PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>; +type OpaqueData = UnsafeCell, PhantomPinned)>>; #[cfg(test)] mod tests { diff --git a/objc2-foundation/src/array.rs b/objc2-foundation/src/array.rs index 1dba1e2a6..d84015725 100644 --- a/objc2-foundation/src/array.rs +++ b/objc2-foundation/src/array.rs @@ -43,19 +43,10 @@ unsafe impl Send for NSArray {} object! { // TODO: Ensure that this deref to NSArray is safe! - unsafe pub struct NSMutableArray: NSArray { - item: PhantomData>, - } + // This "inherits" NSArray, and has the same `Send`/`Sync` impls as that. + unsafe pub struct NSMutableArray: NSArray {} } -// SAFETY: Same as NSArray. -// -// TODO: Properly verify this -unsafe impl Sync for NSMutableArray {} -unsafe impl Send for NSMutableArray {} -unsafe impl Sync for NSMutableArray {} -unsafe impl Send for NSMutableArray {} - unsafe fn from_refs(cls: &Class, refs: &[&T]) -> NonNull { let obj: *mut Object = unsafe { msg_send![cls, alloc] }; let obj: *mut Object = unsafe { diff --git a/objc2/src/rc/id.rs b/objc2/src/rc/id.rs index 01c3c215c..79ba29cfe 100644 --- a/objc2/src/rc/id.rs +++ b/objc2/src/rc/id.rs @@ -2,8 +2,8 @@ use core::fmt; use core::marker::PhantomData; use core::mem::ManuallyDrop; use core::ops::{Deref, DerefMut}; +use core::panic::{RefUnwindSafe, UnwindSafe}; use core::ptr::NonNull; -use std::panic::{RefUnwindSafe, UnwindSafe}; use super::AutoreleasePool; use super::{Owned, Ownership, Shared}; @@ -117,6 +117,11 @@ pub struct Id { item: PhantomData, /// To prevent warnings about unused type parameters. own: PhantomData, + /// Marks the type as !UnwindSafe. Later on we'll re-enable this. + /// + /// See for why this is + /// required. + notunwindsafe: PhantomData<&'static mut ()>, } impl Id { @@ -171,6 +176,7 @@ impl Id { ptr, item: PhantomData, own: PhantomData, + notunwindsafe: PhantomData, } } diff --git a/tests/ui/nsarray_bound_not_send_sync.stderr b/tests/ui/nsarray_bound_not_send_sync.stderr index 2d9dbd17d..169e81d06 100644 --- a/tests/ui/nsarray_bound_not_send_sync.stderr +++ b/tests/ui/nsarray_bound_not_send_sync.stderr @@ -1,30 +1,10 @@ -error[E0277]: `UnsafeCell<()>` cannot be shared between threads safely +error[E0277]: `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely --> ui/nsarray_bound_not_send_sync.rs:9:5 | 9 | needs_sync::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<()>` cannot be shared between threads safely + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely | - = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` - = note: required because it appears within the type `objc_object` - = note: required because it appears within the type `objc2::runtime::Object` - = note: required because of the requirements on the impl of `Sync` for `NSArray` -note: required by a bound in `needs_sync` - --> ui/nsarray_bound_not_send_sync.rs:5:27 - | -5 | fn needs_sync() {} - | ^^^^ required by this bound in `needs_sync` - -error[E0277]: `*const UnsafeCell<()>` cannot be shared between threads safely - --> ui/nsarray_bound_not_send_sync.rs:9:5 - | -9 | needs_sync::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be shared between threads safely - | - = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` = note: required because of the requirements on the impl of `Sync` for `NSArray` @@ -41,8 +21,9 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely | = help: within `objc2::runtime::Object`, the trait `Send` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` + = note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` = note: required because of the requirements on the impl of `Sync` for `NSArray` @@ -52,33 +33,13 @@ note: required by a bound in `needs_sync` 5 | fn needs_sync() {} | ^^^^ required by this bound in `needs_sync` -error[E0277]: `UnsafeCell<()>` cannot be shared between threads safely - --> ui/nsarray_bound_not_send_sync.rs:10:5 - | -10 | needs_send::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<()>` cannot be shared between threads safely - | - = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` - = note: required because it appears within the type `objc_object` - = note: required because it appears within the type `objc2::runtime::Object` - = note: required because of the requirements on the impl of `Send` for `NSArray` -note: required by a bound in `needs_send` - --> ui/nsarray_bound_not_send_sync.rs:6:27 - | -6 | fn needs_send() {} - | ^^^^ required by this bound in `needs_send` - -error[E0277]: `*const UnsafeCell<()>` cannot be shared between threads safely +error[E0277]: `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely --> ui/nsarray_bound_not_send_sync.rs:10:5 | 10 | needs_send::>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be shared between threads safely + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely | - = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` = note: required because of the requirements on the impl of `Send` for `NSArray` @@ -95,8 +56,9 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely | = help: within `objc2::runtime::Object`, the trait `Send` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` + = note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` = note: required because of the requirements on the impl of `Send` for `NSArray` diff --git a/tests/ui/object_not_send_sync.stderr b/tests/ui/object_not_send_sync.stderr index ee1b3b516..5d67650a8 100644 --- a/tests/ui/object_not_send_sync.stderr +++ b/tests/ui/object_not_send_sync.stderr @@ -1,29 +1,10 @@ -error[E0277]: `UnsafeCell<()>` cannot be shared between threads safely +error[E0277]: `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely --> ui/object_not_send_sync.rs:11:5 | 11 | needs_sync::(); - | ^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<()>` cannot be shared between threads safely + | ^^^^^^^^^^^^^^^^^^^^ `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely | - = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` - = note: required because it appears within the type `objc_object` - = note: required because it appears within the type `objc2::runtime::Object` -note: required by a bound in `needs_sync` - --> ui/object_not_send_sync.rs:7:27 - | -7 | fn needs_sync() {} - | ^^^^ required by this bound in `needs_sync` - -error[E0277]: `*const UnsafeCell<()>` cannot be shared between threads safely - --> ui/object_not_send_sync.rs:11:5 - | -11 | needs_sync::(); - | ^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be shared between threads safely - | - = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = help: within `objc2::runtime::Object`, the trait `Sync` is not implemented for `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` note: required by a bound in `needs_sync` @@ -39,8 +20,9 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely | ^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely | = help: within `objc2::runtime::Object`, the trait `Send` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` + = note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` note: required by a bound in `needs_send` @@ -49,33 +31,13 @@ note: required by a bound in `needs_send` 8 | fn needs_send() {} | ^^^^ required by this bound in `needs_send` -error[E0277]: `UnsafeCell<()>` cannot be shared between threads safely - --> ui/object_not_send_sync.rs:13:5 - | -13 | needs_sync::(); - | ^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell<()>` cannot be shared between threads safely - | - = help: within `NSObject`, the trait `Sync` is not implemented for `UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` - = note: required because it appears within the type `objc_object` - = note: required because it appears within the type `objc2::runtime::Object` - = note: required because it appears within the type `NSObject` -note: required by a bound in `needs_sync` - --> ui/object_not_send_sync.rs:7:27 - | -7 | fn needs_sync() {} - | ^^^^ required by this bound in `needs_sync` - -error[E0277]: `*const UnsafeCell<()>` cannot be shared between threads safely +error[E0277]: `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely --> ui/object_not_send_sync.rs:13:5 | 13 | needs_sync::(); - | ^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be shared between threads safely + | ^^^^^^^^^^^^^^^^^^^^^^ `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely | - = help: within `NSObject`, the trait `Sync` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = help: within `NSObject`, the trait `Sync` is not implemented for `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` = note: required because it appears within the type `NSObject` @@ -92,8 +54,9 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely | ^^^^^^^^^^^^^^^^^^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely | = help: within `NSObject`, the trait `Send` is not implemented for `*const UnsafeCell<()>` - = note: required because it appears within the type `(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)` - = note: required because it appears within the type `PhantomData<(UnsafeCell<()>, *const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` + = note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` + = note: required because it appears within the type `UnsafeCell, PhantomPinned)>>` = note: required because it appears within the type `objc_object` = note: required because it appears within the type `objc2::runtime::Object` = note: required because it appears within the type `NSObject`