diff --git a/crates/icrate/src/fixes/Foundation/copying.rs b/crates/icrate/src/fixes/Foundation/copying.rs index b0d7c8ef4..4f8f4183a 100644 --- a/crates/icrate/src/fixes/Foundation/copying.rs +++ b/crates/icrate/src/fixes/Foundation/copying.rs @@ -22,7 +22,6 @@ extern_protocol!( #[optional] fn copy(&self) -> Id where - Self: Sized, Self: CounterpartOrSelf; /// Returns a new instance that's a copy of the receiver. @@ -37,7 +36,6 @@ extern_protocol!( #[method_id(copyWithZone:)] unsafe fn copyWithZone(&self, zone: *mut NSZone) -> Id where - Self: Sized, Self: CounterpartOrSelf; } @@ -65,7 +63,6 @@ extern_protocol!( #[optional] fn mutableCopy(&self) -> Id where - Self: Sized, Self: CounterpartOrSelf; /// Returns a new instance that's a mutable copy of the receiver. @@ -80,7 +77,6 @@ extern_protocol!( #[method_id(mutableCopyWithZone:)] unsafe fn mutableCopyWithZone(&self, zone: *mut NSZone) -> Id where - Self: Sized, Self: CounterpartOrSelf; } diff --git a/crates/objc2/CHANGELOG.md b/crates/objc2/CHANGELOG.md index e604ad0f5..931643621 100644 --- a/crates/objc2/CHANGELOG.md +++ b/crates/objc2/CHANGELOG.md @@ -22,6 +22,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Added `Allocated::set_ivars`, which sets the instance variables of an object, and returns the new `rc::PartialInit`. * Added the ability for `msg_send_id!` to call `super` methods. +* Implement `Send` and `Sync` for `ProtocolObject` if the underlying protocol + implements it. +* Added ability to create `Send` and `Sync` versions of + `ProtocolObject`. ### Changed * **BREAKING**: Changed how instance variables work in `declare_class!`. @@ -149,6 +153,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * **BREAKING**: Make `rc::Allocated` allowed to be `NULL` internally, such that uses of `Option>` is now simply `Allocated`. * `AnyObject::class` now returns a `'static` reference to the class. +* Relaxed `ProtocolType` requirement on `ProtocolObject`. ### Deprecated * Soft deprecated using `msg_send!` without a comma between arguments (i.e. diff --git a/crates/objc2/src/macros/extern_protocol.rs b/crates/objc2/src/macros/extern_protocol.rs index 5418fb52a..1a99770a0 100644 --- a/crates/objc2/src/macros/extern_protocol.rs +++ b/crates/objc2/src/macros/extern_protocol.rs @@ -184,7 +184,7 @@ macro_rules! __inner_extern_protocol { $(#[$impl_m])* unsafe impl $name for $crate::runtime::ProtocolObject where - T: ?$crate::__macro_helpers::Sized + $crate::ProtocolType + $name + T: ?$crate::__macro_helpers::Sized + $name {} // SAFETY: The specified name is ensured by caller to be a protocol, @@ -204,6 +204,9 @@ macro_rules! __inner_extern_protocol { { const __INNER: () = (); } + + // TODO: Should we also implement `ImplementedBy` for `Send + Sync` + // types, as is done for `NSObjectProtocol`? }; } diff --git a/crates/objc2/src/mutability.rs b/crates/objc2/src/mutability.rs index f2d707ecb..0bc764084 100644 --- a/crates/objc2/src/mutability.rs +++ b/crates/objc2/src/mutability.rs @@ -33,7 +33,7 @@ use core::marker::PhantomData; use crate::runtime::{AnyObject, ProtocolObject}; -use crate::{ClassType, Message, ProtocolType}; +use crate::{ClassType, Message}; mod private_mutability { pub trait Sealed {} @@ -269,7 +269,7 @@ mod private_traits { } impl private_traits::Sealed for T {} -impl private_traits::Sealed for ProtocolObject

{} +impl private_traits::Sealed for ProtocolObject

{} impl private_traits::Sealed for AnyObject {} /// Marker trait for classes where [`Id::clone`] is safe. @@ -303,7 +303,7 @@ impl MutabilityIsIdCloneable for InteriorMutable {} impl MutabilityIsIdCloneable for MainThreadOnly {} unsafe impl IsIdCloneable for T where T::Mutability: MutabilityIsIdCloneable {} -unsafe impl IsIdCloneable for ProtocolObject

{} +unsafe impl IsIdCloneable for ProtocolObject

{} // SAFETY: Same as for root classes. unsafe impl IsIdCloneable for AnyObject {} @@ -336,7 +336,7 @@ impl MutabilityIsRetainable for InteriorMutable {} impl MutabilityIsRetainable for MainThreadOnly {} unsafe impl IsRetainable for T where T::Mutability: MutabilityIsRetainable {} -unsafe impl IsRetainable for ProtocolObject

{} +unsafe impl IsRetainable for ProtocolObject

{} /// Marker trait for classes that can be allocated from any thread. /// @@ -367,10 +367,7 @@ unsafe impl IsAllocableAnyThread for T where T::Mutability: MutabilityIsAllocableAnyThread { } -unsafe impl IsAllocableAnyThread - for ProtocolObject

-{ -} +unsafe impl IsAllocableAnyThread for ProtocolObject

{} /// Marker trait for classes that may feasibly be used behind a mutable /// reference. @@ -401,7 +398,7 @@ unsafe impl IsAllowedMutable for T where T::Mutability: MutabilityIsAllowedMutable { } -unsafe impl IsAllowedMutable for ProtocolObject

{} +unsafe impl IsAllowedMutable for ProtocolObject

{} // SAFETY: Same as for root classes. unsafe impl IsAllowedMutable for AnyObject {} @@ -430,7 +427,7 @@ impl MutabilityIsMutable for Mutable {} impl MutabilityIsMutable for MutableWithImmutableSuperclass {} unsafe impl IsMutable for T where T::Mutability: MutabilityIsMutable {} -unsafe impl IsMutable for ProtocolObject

{} +unsafe impl IsMutable for ProtocolObject

{} /// Marker trait for classes that are only available on the main thread. /// @@ -455,7 +452,7 @@ unsafe impl IsMainThreadOnly for T where T::Mutability: MutabilityIsMainThreadOnly { } -unsafe impl IsMainThreadOnly for ProtocolObject

{} +unsafe impl IsMainThreadOnly for ProtocolObject

{} /// Marker trait for classes whose `hash` and `isEqual:` methods are stable. /// @@ -489,7 +486,7 @@ impl MutabilityHashIsStable for ImmutableWithMutableSubclass {} impl MutabilityHashIsStable for MutableWithImmutableSuperclass {} unsafe impl HasStableHash for T where T::Mutability: MutabilityHashIsStable {} -unsafe impl HasStableHash for ProtocolObject

{} +unsafe impl HasStableHash for ProtocolObject

{} /// Retrieve the immutable/mutable counterpart class, and fall back to `Self` /// if not applicable. @@ -589,7 +586,7 @@ where type Mutable = >::Mutable; } -unsafe impl CounterpartOrSelf for ProtocolObject

{ +unsafe impl CounterpartOrSelf for ProtocolObject

{ // SAFETY: The only place where this would differ from `Self` is for // classes with `MutableWithImmutableSuperclass`. // diff --git a/crates/objc2/src/runtime/nsobject.rs b/crates/objc2/src/runtime/nsobject.rs index 3672a5c85..deb48c856 100644 --- a/crates/objc2/src/runtime/nsobject.rs +++ b/crates/objc2/src/runtime/nsobject.rs @@ -7,6 +7,8 @@ use crate::runtime::{AnyClass, AnyObject, ProtocolObject}; use crate::{extern_methods, msg_send, msg_send_id, Message}; use crate::{ClassType, ProtocolType}; +use super::ImplementedBy; + /// The root class of most Objective-C class hierarchies. /// /// This represents the [`NSObject` class][cls]. The name "NSObject" also @@ -163,6 +165,33 @@ crate::__inner_extern_protocol!( ("NSObject") ); +// SAFETY: Anything that implements `NSObjectProtocol` and is `Send` is valid +// to convert to `ProtocolObject`. +unsafe impl ImplementedBy for dyn NSObjectProtocol + Send +where + T: ?Sized + Message + NSObjectProtocol + Send, +{ + const __INNER: () = (); +} + +// SAFETY: Anything that implements `NSObjectProtocol` and is `Sync` is valid +// to convert to `ProtocolObject`. +unsafe impl ImplementedBy for dyn NSObjectProtocol + Sync +where + T: ?Sized + Message + NSObjectProtocol + Sync, +{ + const __INNER: () = (); +} + +// SAFETY: Anything that implements `NSObjectProtocol` and is `Send + Sync` is +// valid to convert to `ProtocolObject`. +unsafe impl ImplementedBy for dyn NSObjectProtocol + Send + Sync +where + T: ?Sized + Message + NSObjectProtocol + Send + Sync, +{ + const __INNER: () = (); +} + unsafe impl NSObjectProtocol for NSObject {} extern_methods!( diff --git a/crates/objc2/src/runtime/protocol_object.rs b/crates/objc2/src/runtime/protocol_object.rs index 46ff46c29..384ebf99c 100644 --- a/crates/objc2/src/runtime/protocol_object.rs +++ b/crates/objc2/src/runtime/protocol_object.rs @@ -7,7 +7,7 @@ use crate::encode::{Encoding, RefEncode}; use crate::rc::{autoreleasepool_leaking, Id}; use crate::runtime::__nsstring::nsstring_to_str; use crate::runtime::{AnyObject, NSObjectProtocol}; -use crate::{Message, ProtocolType}; +use crate::Message; /// An internal helper trait for [`ProtocolObject`]. /// @@ -57,25 +57,35 @@ pub unsafe trait ImplementedBy { /// ``` #[doc(alias = "id")] #[repr(C)] -pub struct ProtocolObject { +pub struct ProtocolObject { inner: AnyObject, p: PhantomData

, } +// SAFETY: `Send` if the underlying trait promises `Send`. +// +// E.g. `ProtocolObject` is naturally `Send`. +unsafe impl Send for ProtocolObject

{} + +// SAFETY: `Sync` if the underlying trait promises `Sync`. +// +// E.g. `ProtocolObject` is naturally `Sync`. +unsafe impl Sync for ProtocolObject

{} + // SAFETY: The type is `#[repr(C)]` and `AnyObject` internally -unsafe impl RefEncode for ProtocolObject

{ +unsafe impl RefEncode for ProtocolObject

{ const ENCODING_REF: Encoding = Encoding::Object; } // SAFETY: The type is `AnyObject` internally, and is mean to be messaged // as-if it's an object. -unsafe impl Message for ProtocolObject

{} +unsafe impl Message for ProtocolObject

{} -impl ProtocolObject

{ +impl ProtocolObject

{ /// Get an immutable type-erased reference from a type implementing a /// protocol. #[inline] - pub fn from_ref(obj: &T) -> &Self + pub fn from_ref(obj: &T) -> &Self where P: ImplementedBy, { @@ -89,7 +99,7 @@ impl ProtocolObject

{ /// Get a mutable type-erased reference from a type implementing a /// protocol. #[inline] - pub fn from_mut(obj: &mut T) -> &mut Self + pub fn from_mut(obj: &mut T) -> &mut Self where P: ImplementedBy, { @@ -118,7 +128,7 @@ impl ProtocolObject

{ } } -impl PartialEq for ProtocolObject

{ +impl PartialEq for ProtocolObject

{ #[inline] #[doc(alias = "isEqual:")] fn eq(&self, other: &Self) -> bool { @@ -126,16 +136,16 @@ impl PartialEq for ProtocolObject

Eq for ProtocolObject

{} +impl Eq for ProtocolObject

{} -impl hash::Hash for ProtocolObject

{ +impl hash::Hash for ProtocolObject

{ #[inline] fn hash(&self, state: &mut H) { self.__hash().hash(state); } } -impl fmt::Debug for ProtocolObject

{ +impl fmt::Debug for ProtocolObject

{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Attempt to format description string if let Some(description) = self.__description() { @@ -159,10 +169,9 @@ impl fmt::Debug for ProtocolObject< } } -impl AsRef> for ProtocolObject

+impl AsRef> for ProtocolObject

where - P: ?Sized + ProtocolType, - T: ?Sized + ProtocolType + ImplementedBy>, + T: ?Sized + ImplementedBy>, { #[inline] fn as_ref(&self) -> &ProtocolObject { @@ -170,10 +179,9 @@ where } } -impl AsMut> for ProtocolObject

+impl AsMut> for ProtocolObject

where - P: ?Sized + ProtocolType, - T: ?Sized + ProtocolType + ImplementedBy>, + T: ?Sized + ImplementedBy>, { #[inline] fn as_mut(&mut self) -> &mut ProtocolObject { @@ -181,7 +189,7 @@ where } } -// TODO: Maybe iplement Borrow + BorrowMut? +// TODO: Maybe implement Borrow + BorrowMut? #[cfg(test)] #[allow(clippy::missing_safety_doc)] @@ -194,7 +202,9 @@ mod tests { use super::*; use crate::mutability::Mutable; use crate::runtime::{NSObject, NSObjectProtocol}; - use crate::{declare_class, extern_methods, extern_protocol, ClassType, DeclaredClass}; + use crate::{ + declare_class, extern_methods, extern_protocol, ClassType, DeclaredClass, ProtocolType, + }; extern_protocol!( unsafe trait Foo { @@ -264,6 +274,9 @@ mod tests { unsafe impl FooBar for DummyClass {} // unsafe impl FooFooBar for DummyClass {} + unsafe impl Send for DummyClass {} + unsafe impl Sync for DummyClass {} + extern_methods!( unsafe impl DummyClass { #[method_id(new)] @@ -275,6 +288,12 @@ mod tests { fn impl_traits() { assert_impl_all!(NSObject: NSObjectProtocol); assert_impl_all!(ProtocolObject: NSObjectProtocol); + assert_not_impl_any!(ProtocolObject: Send, Sync); + assert_impl_all!(ProtocolObject: NSObjectProtocol, Send); + assert_not_impl_any!(ProtocolObject: Sync); + assert_impl_all!(ProtocolObject: NSObjectProtocol, Sync); + assert_not_impl_any!(ProtocolObject: Send); + assert_impl_all!(ProtocolObject: NSObjectProtocol, Send, Sync); assert_not_impl_any!(ProtocolObject: NSObjectProtocol); assert_impl_all!(ProtocolObject: NSObjectProtocol); assert_impl_all!(ProtocolObject: NSObjectProtocol); @@ -332,6 +351,10 @@ mod tests { let _nsobject: &ProtocolObject = ProtocolObject::from_ref(bar); let nsobject: &ProtocolObject = ProtocolObject::from_ref(&*obj); let _nsobject: &ProtocolObject = ProtocolObject::from_ref(nsobject); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + let _: &ProtocolObject = + ProtocolObject::from_ref(&*obj); let _foobar: &mut ProtocolObject = ProtocolObject::from_mut(&mut *obj); let _foobar: Id> = ProtocolObject::from_id(obj); diff --git a/crates/test-ui/ui/protocol_object_only_protocols.rs b/crates/test-ui/ui/protocol_object_only_protocols.rs new file mode 100644 index 000000000..03980b90d --- /dev/null +++ b/crates/test-ui/ui/protocol_object_only_protocols.rs @@ -0,0 +1,27 @@ +//! Ensure that `ProtocolObject` cannot be incorrectly constructed. +use icrate::Foundation::NSCopying; +use objc2::runtime::{NSObject, NSObjectProtocol, ProtocolObject}; + +trait Foo { + fn foo(&self) {} +} + +impl Foo for T {} + +fn main() { + let obj = NSObject::new(); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + + // `NSObject` is neither `Send` nor `Sync`. + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + + // `NSObject` is not `NSCopying`. + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + + // `dyn NSCopying + Send` does not implement `ImplementedBy` (yet). + let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); +} diff --git a/crates/test-ui/ui/protocol_object_only_protocols.stderr b/crates/test-ui/ui/protocol_object_only_protocols.stderr new file mode 100644 index 000000000..038ea3af0 --- /dev/null +++ b/crates/test-ui/ui/protocol_object_only_protocols.stderr @@ -0,0 +1,333 @@ +error[E0277]: the trait bound `NSObject: ImplementedBy` is not satisfied + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ the trait `ImplementedBy` is not implemented for `NSObject` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: the trait bound `dyn Send: ImplementedBy` is not satisfied + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ the trait `ImplementedBy` is not implemented for `dyn Send` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: the trait bound `dyn Foo: ImplementedBy` is not satisfied + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ the trait `ImplementedBy` is not implemented for `dyn Foo` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: within `NSObject`, the trait `Send` is not implemented for `*const UnsafeCell<()>` + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others + = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` +note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` + --> $RUST/core/src/marker.rs + | + | pub struct PhantomData; + | ^^^^^^^^^^^ +note: required because it appears within the type `UnsafeCell, PhantomPinned)>>` + --> $RUST/core/src/cell.rs + | + | pub struct UnsafeCell { + | ^^^^^^^^^^ +note: required because it appears within the type `objc_object` + --> $WORKSPACE/crates/objc-sys/src/object.rs + | + | pub struct objc_object { + | ^^^^^^^^^^^ +note: required because it appears within the type `AnyObject` + --> $WORKSPACE/crates/objc2/src/runtime/mod.rs + | + | pub struct AnyObject(ffi::objc_object); + | ^^^^^^^^^ +note: required because it appears within the type `NSObject` + --> $WORKSPACE/crates/objc2/src/runtime/nsobject.rs + | + | pub struct NSObject { + | ^^^^^^^^ + = note: required for `dyn NSObjectProtocol + Send` to implement `ImplementedBy` +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely + | | + | required by a bound introduced by this call + | + = help: within `NSObject`, the trait `Sync` is not implemented for `UnsafeCell, PhantomPinned)>>` + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others +note: required because it appears within the type `objc_object` + --> $WORKSPACE/crates/objc-sys/src/object.rs + | + | pub struct objc_object { + | ^^^^^^^^^^^ +note: required because it appears within the type `AnyObject` + --> $WORKSPACE/crates/objc2/src/runtime/mod.rs + | + | pub struct AnyObject(ffi::objc_object); + | ^^^^^^^^^ +note: required because it appears within the type `NSObject` + --> $WORKSPACE/crates/objc2/src/runtime/nsobject.rs + | + | pub struct NSObject { + | ^^^^^^^^ + = note: required for `dyn NSObjectProtocol + Sync` to implement `ImplementedBy` +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ `UnsafeCell, PhantomPinned)>>` cannot be shared between threads safely + | | + | required by a bound introduced by this call + | + = help: within `NSObject`, the trait `Sync` is not implemented for `UnsafeCell, PhantomPinned)>>` + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others +note: required because it appears within the type `objc_object` + --> $WORKSPACE/crates/objc-sys/src/object.rs + | + | pub struct objc_object { + | ^^^^^^^^^^^ +note: required because it appears within the type `AnyObject` + --> $WORKSPACE/crates/objc2/src/runtime/mod.rs + | + | pub struct AnyObject(ffi::objc_object); + | ^^^^^^^^^ +note: required because it appears within the type `NSObject` + --> $WORKSPACE/crates/objc2/src/runtime/nsobject.rs + | + | pub struct NSObject { + | ^^^^^^^^ + = note: required for `dyn NSObjectProtocol + Send + Sync` to implement `ImplementedBy` +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ `*const UnsafeCell<()>` cannot be sent between threads safely + | | + | required by a bound introduced by this call + | + = help: within `NSObject`, the trait `Send` is not implemented for `*const UnsafeCell<()>` + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others + = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` +note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` + --> $RUST/core/src/marker.rs + | + | pub struct PhantomData; + | ^^^^^^^^^^^ +note: required because it appears within the type `UnsafeCell, PhantomPinned)>>` + --> $RUST/core/src/cell.rs + | + | pub struct UnsafeCell { + | ^^^^^^^^^^ +note: required because it appears within the type `objc_object` + --> $WORKSPACE/crates/objc-sys/src/object.rs + | + | pub struct objc_object { + | ^^^^^^^^^^^ +note: required because it appears within the type `AnyObject` + --> $WORKSPACE/crates/objc2/src/runtime/mod.rs + | + | pub struct AnyObject(ffi::objc_object); + | ^^^^^^^^^ +note: required because it appears within the type `NSObject` + --> $WORKSPACE/crates/objc2/src/runtime/nsobject.rs + | + | pub struct NSObject { + | ^^^^^^^^ + = note: required for `dyn NSObjectProtocol + Send + Sync` to implement `ImplementedBy` +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: the trait bound `NSObject: NSCopying` is not satisfied + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ the trait `NSCopying` is not implemented for `NSObject` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `NSCopying`: + ProtocolObject + __RcTestObject + NSCollectionLayoutSection + NSCollectionLayoutGroupCustomItem + NSArray + NSMutableArray + NSDictionary + NSSet + and $N others + = note: required for `dyn NSCopying` to implement `ImplementedBy` +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref` + +error[E0277]: the trait bound `dyn NSCopying + Send: ImplementedBy` is not satisfied + --> ui/protocol_object_only_protocols.rs + | + | let _: &ProtocolObject = ProtocolObject::from_ref(&*obj); + | ------------------------ ^^^^^ the trait `ImplementedBy` is not implemented for `dyn NSCopying + Send` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `ImplementedBy`: + (dyn NSObjectProtocol + 'static) + (dyn NSObjectProtocol + Send + 'static) + (dyn NSObjectProtocol + Sync + 'static) + (dyn NSObjectProtocol + Send + Sync + 'static) + (dyn NSAccessibilityColor + 'static) + (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) + (dyn NSAccessibilityElementProtocol + 'static) + (dyn NSAccessibilityGroup + 'static) + and $N others +note: required by a bound in `ProtocolObject::

::from_ref` + --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs + | + | pub fn from_ref(obj: &T) -> &Self + | -------- required by a bound in this associated function + | where + | P: ImplementedBy, + | ^^^^^^^^^^^^^^^^ required by this bound in `ProtocolObject::

::from_ref`