From 3730c60a5a2778e469bc121969d27f5cc35f37db Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 4 Feb 2023 01:23:02 +0100 Subject: [PATCH] TMP --- crates/objc2/src/{class_type.rs => class.rs} | 63 ++++++++++++++++++- crates/objc2/src/declare.rs | 12 +++- .../objc2/src/declare/declare_class_tests.rs | 12 +++- crates/objc2/src/declare/ivar.rs | 4 +- crates/objc2/src/declare/ivar_drop.rs | 5 +- crates/objc2/src/lib.rs | 8 ++- crates/objc2/src/macros.rs | 5 +- crates/objc2/src/macros/declare_class.rs | 25 ++++++-- crates/objc2/src/macros/extern_class.rs | 21 +++++-- crates/objc2/src/macros/extern_methods.rs | 4 +- crates/objc2/src/protocol.rs | 4 +- crates/objc2/src/rc/test_object.rs | 5 +- crates/objc2/src/runtime/nsobject.rs | 8 +-- crates/objc2/tests/declare_class_self.rs | 5 +- crates/objc2/tests/no_prelude.rs | 2 + crates/objc2/tests/track_caller.rs | 4 +- 16 files changed, 160 insertions(+), 27 deletions(-) rename crates/objc2/src/{class_type.rs => class.rs} (66%) diff --git a/crates/objc2/src/class_type.rs b/crates/objc2/src/class.rs similarity index 66% rename from crates/objc2/src/class_type.rs rename to crates/objc2/src/class.rs index da35606dc..73135aff5 100644 --- a/crates/objc2/src/class_type.rs +++ b/crates/objc2/src/class.rs @@ -3,6 +3,46 @@ use crate::rc::{Allocated, Id, Ownership}; use crate::runtime::Class; use crate::Message; +mod private { + pub trait Sealed {} +} + +pub unsafe trait Retainable: private::Sealed {} +pub trait ClassKind: private::Sealed {} + +// Fallback for everything that hasn't been specified +pub struct Unknown; +impl private::Sealed for Unknown {} +impl ClassKind for Unknown {} + +/// `Id::retain` is safe +pub struct Immutable; +impl private::Sealed for Immutable {} +unsafe impl Retainable for Immutable {} +impl ClassKind for Immutable {} + +/// Immutable, but disallows `Id::retain` +pub struct ImmutableWithMutableSubclass; +impl private::Sealed for ImmutableWithMutableSubclass {} +impl ClassKind for ImmutableWithMutableSubclass {} + +/// Mutable, mutable methods use `&mut self`. `Id::retain` is not safe +pub struct Mutable; +impl private::Sealed for Mutable {} +impl ClassKind for Mutable {} + +/// Mutable, mutable methods use `&self`. Not Send + Sync. `Id::retain` is safe +pub struct InteriorMutable; +impl private::Sealed for InteriorMutable {} +unsafe impl Retainable for InteriorMutable {} +impl ClassKind for InteriorMutable {} + +/// Same as InteriorMutable, but only on the main thread. `Id::retain` is safe +pub struct MainThreadOnly; +impl private::Sealed for MainThreadOnly {} +unsafe impl Retainable for MainThreadOnly {} +impl ClassKind for MainThreadOnly {} + /// Marks types that represent specific classes. /// /// Usually it is enough to generically know that a type is messageable, e.g. @@ -44,13 +84,15 @@ use crate::Message; /// trait for a type. /// /// ```ignore -/// use objc2::{extern_class, ClassType}; +/// use objc2::class::{ClassType, Unknown}; +/// use objc2::extern_class; /// /// extern_class!( /// struct MyClass; /// /// unsafe impl ClassType for MyClass { /// type Super = NSObject; +/// type Kind = Unknown; /// } /// ); /// @@ -69,6 +111,8 @@ pub unsafe trait ClassType: Message { /// [`runtime::Object`]: crate::runtime::Object type Super: Message; + type Kind: ClassKind; + /// The name of the Objective-C class that this type represents. const NAME: &'static str; @@ -106,6 +150,23 @@ pub unsafe trait ClassType: Message { // from `Self::class`. unsafe { msg_send_id![Self::class(), alloc] } } + + fn retain(&self) -> Id + where + Self::Kind: Retainable, + Self: 'static, + { + let ptr: *const Self = self; + let ptr: *mut Self = ptr as _; + // SAFETY: + // - The ownership is correct due to the `Kind: Retainable` bound. + // - The pointer is valid since it came from `&self`. + // - Self is `'static`, so extending the lifetime of the object here + // is fine. + let obj = unsafe { Id::retain(ptr) }; + // SAFETY: The pointer came from `&self`, which is always non-null + unsafe { obj.unwrap_unchecked() } + } } impl Id diff --git a/crates/objc2/src/declare.rs b/crates/objc2/src/declare.rs index ed87acd5a..41ebf01ed 100644 --- a/crates/objc2/src/declare.rs +++ b/crates/objc2/src/declare.rs @@ -692,10 +692,12 @@ impl ProtocolBuilder { #[cfg(test)] mod tests { use super::*; + use crate::class::{ClassType, Immutable}; + use crate::protocol::ProtocolType; use crate::rc::Id; use crate::runtime::{NSObject, NSZone}; use crate::test_utils; - use crate::{declare_class, extern_protocol, msg_send, ClassType, ProtocolType}; + use crate::{declare_class, extern_protocol, msg_send}; extern_protocol!( #[allow(clippy::missing_safety_doc)] @@ -848,6 +850,7 @@ mod tests { unsafe impl ClassType for Custom1 { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassDuplicate"; } ); @@ -857,6 +860,7 @@ mod tests { unsafe impl ClassType for Custom2 { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassDuplicate"; } ); @@ -873,6 +877,7 @@ mod tests { unsafe impl ClassType for Custom { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassProtocolNotFound"; } @@ -899,6 +904,7 @@ mod tests { unsafe impl ClassType for Custom { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassInvalidMethod"; } @@ -923,6 +929,7 @@ mod tests { unsafe impl ClassType for Custom { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassMissingProtocolMethod"; } @@ -942,6 +949,7 @@ mod tests { unsafe impl ClassType for Custom { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassInvalidProtocolMethod"; } @@ -968,6 +976,7 @@ mod tests { unsafe impl ClassType for Custom { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestDeclareClassExtraProtocolMethod"; } @@ -998,6 +1007,7 @@ mod tests { unsafe impl ClassType for GenericDeclareClass { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "GenericDeclareClass"; #[inline] diff --git a/crates/objc2/src/declare/declare_class_tests.rs b/crates/objc2/src/declare/declare_class_tests.rs index 971f0dca8..b6247421b 100644 --- a/crates/objc2/src/declare/declare_class_tests.rs +++ b/crates/objc2/src/declare/declare_class_tests.rs @@ -1,10 +1,11 @@ #![deny(deprecated, unreachable_code)] use core::ptr; +use crate::class::{ClassType, Immutable, Mutable}; use crate::declare::IvarEncode; use crate::rc::{Id, Owned}; use crate::runtime::NSObject; -use crate::{declare_class, extern_methods, sel, ClassType}; +use crate::{declare_class, extern_methods, sel}; // Test that adding the `deprecated` attribute does not mean that warnings // when using the method internally are output. @@ -14,6 +15,7 @@ declare_class!( unsafe impl ClassType for DeclareClassDepreactedMethod { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "DeclareClassDepreactedMethod"; } @@ -44,6 +46,7 @@ declare_class!( unsafe impl ClassType for DeclareClassCfg { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "DeclareClassCfg"; } @@ -185,6 +188,7 @@ declare_class!( unsafe impl ClassType for TestMultipleColonSelector { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "TestMultipleColonSelector"; } @@ -257,6 +261,7 @@ declare_class!( unsafe impl ClassType for DeclareClassAllTheBool { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "DeclareClassAllTheBool"; } @@ -319,6 +324,7 @@ declare_class!( unsafe impl ClassType for DeclareClassUnreachable { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "DeclareClassUnreachable"; } @@ -374,6 +380,7 @@ fn test_duplicate_ivar() { unsafe impl ClassType for DeclareClassDuplicateIvar { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "DeclareClassDuplicateIvar"; } ); @@ -393,6 +400,7 @@ fn test_subclass_duplicate_ivar() { unsafe impl ClassType for Cls { type Super = NSObject; + type Kind = Mutable; const NAME: &'static str = "DeclareClassDuplicateIvarSuperclass"; } ); @@ -406,6 +414,7 @@ fn test_subclass_duplicate_ivar() { unsafe impl ClassType for SubCls { type Super = Cls; + type Kind = Mutable; const NAME: &'static str = "DeclareClassDuplicateIvarSubclass"; } ); @@ -450,6 +459,7 @@ declare_class!( unsafe impl ClassType for OutParam { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "OutParam"; } diff --git a/crates/objc2/src/declare/ivar.rs b/crates/objc2/src/declare/ivar.rs index 34865ed9e..bb334c32b 100644 --- a/crates/objc2/src/declare/ivar.rs +++ b/crates/objc2/src/declare/ivar.rs @@ -317,10 +317,11 @@ mod tests { use std::sync::atomic::{AtomicBool, Ordering}; use super::*; + use crate::class::{ClassType, Mutable}; use crate::declare::{IvarBool, IvarEncode}; use crate::rc::Id; use crate::runtime::NSObject; - use crate::{declare_class, msg_send, msg_send_id, test_utils, ClassType, MessageReceiver}; + use crate::{declare_class, msg_send, msg_send_id, test_utils, MessageReceiver}; struct TestIvar; @@ -374,6 +375,7 @@ mod tests { unsafe impl ClassType for CustomDrop { type Super = NSObject; + type Kind = Mutable; const NAME: &'static str = "CustomDrop"; } ); diff --git a/crates/objc2/src/declare/ivar_drop.rs b/crates/objc2/src/declare/ivar_drop.rs index af030c383..b1d8a30be 100644 --- a/crates/objc2/src/declare/ivar_drop.rs +++ b/crates/objc2/src/declare/ivar_drop.rs @@ -203,11 +203,12 @@ unsafe fn box_unreachable() -> ! { #[cfg(test)] mod tests { use super::*; + use crate::class::{ClassType, Mutable}; use crate::declare::{Ivar, IvarType}; use crate::rc::{Allocated, Owned, __RcTestObject, __ThreadTestData}; use crate::runtime::NSObject; use crate::runtime::Object; - use crate::{declare_class, msg_send, msg_send_id, ClassType}; + use crate::{declare_class, msg_send, msg_send_id}; struct TestIvar1; unsafe impl IvarType for TestIvar1 { @@ -246,6 +247,7 @@ mod tests { unsafe impl ClassType for IvarTester { type Super = NSObject; + type Kind = Mutable; const NAME: &'static str = "IvarTester"; } @@ -282,6 +284,7 @@ mod tests { unsafe impl ClassType for IvarTesterSubclass { type Super = IvarTester; + type Kind = Mutable; const NAME: &'static str = "IvarTesterSubclass"; } diff --git a/crates/objc2/src/lib.rs b/crates/objc2/src/lib.rs index c7a62ee36..fe7a55c1c 100644 --- a/crates/objc2/src/lib.rs +++ b/crates/objc2/src/lib.rs @@ -184,10 +184,12 @@ extern "C" {} #[doc(no_inline)] pub use objc_sys as ffi; -pub use self::class_type::ClassType; +#[doc(no_inline)] +pub use self::class::ClassType; #[doc(no_inline)] pub use self::encode::{Encode, Encoding, RefEncode}; pub use self::message::{Message, MessageArguments, MessageReceiver}; +#[doc(no_inline)] pub use self::protocol::{ImplementedBy, ProtocolObject, ProtocolType}; pub use self::verify::VerificationError; @@ -208,13 +210,13 @@ macro_rules! __hash_idents { #[doc(hidden)] pub mod __macro_helpers; mod cache; -mod class_type; +pub mod class; pub mod declare; pub mod encode; pub mod exception; mod macros; mod message; -mod protocol; +pub mod protocol; pub mod rc; pub mod runtime; #[cfg(test)] diff --git a/crates/objc2/src/macros.rs b/crates/objc2/src/macros.rs index 8366233ef..0e40e08c0 100644 --- a/crates/objc2/src/macros.rs +++ b/crates/objc2/src/macros.rs @@ -887,14 +887,17 @@ macro_rules! __class_inner { /// /// ```no_run /// use objc2::msg_send; +/// # +/// # use objc2::class::{ClassType, Unknown}; /// # use objc2::runtime::NSObject; -/// # use objc2::{declare_class, ClassType}; +/// # use objc2::declare_class; /// # /// # declare_class!( /// # struct MyObject; /// # /// # unsafe impl ClassType for MyObject { /// # type Super = NSObject; +/// # type Kind = Unknown; /// # const NAME: &'static str = "MyObject"; /// # } /// # ); diff --git a/crates/objc2/src/macros/declare_class.rs b/crates/objc2/src/macros/declare_class.rs index d4392a85c..81d7bb005 100644 --- a/crates/objc2/src/macros/declare_class.rs +++ b/crates/objc2/src/macros/declare_class.rs @@ -154,13 +154,12 @@ /// /// ``` /// use std::os::raw::c_int; +/// use objc2::class::{ClassType, Mutable}; /// use objc2::declare::{Ivar, IvarDrop, IvarEncode}; +/// use objc2::protocol::ProtocolType; /// use objc2::rc::{Id, Owned}; /// use objc2::runtime::{NSObject, NSObjectProtocol, NSZone}; -/// use objc2::{ -/// declare_class, extern_protocol, msg_send, msg_send_id, ClassType, -/// ProtocolType, -/// }; +/// use objc2::{declare_class, extern_protocol, msg_send, msg_send_id}; /// /// // Declare the NSCopying protocol so that we can implement it. /// // @@ -189,6 +188,7 @@ /// /// unsafe impl ClassType for MyCustomObject { /// type Super = NSObject; +/// type Kind = Mutable; /// const NAME: &'static str = "MyCustomObject"; /// } /// @@ -362,6 +362,8 @@ macro_rules! declare_class { $(#[inherits($($inheritance_rest:ty),+)])? type Super = $superclass:ty; + type Kind = $kind:ty; + const NAME: &'static str = $name_const:literal; } @@ -386,6 +388,8 @@ macro_rules! declare_class { $(#[inherits($($inheritance_rest),+)])? type Super = $superclass; + type Kind = $kind; + const NAME: &'static str = $name_const; } @@ -404,6 +408,8 @@ macro_rules! declare_class { $(#[inherits($($inheritance_rest:ty),+)])? type Super = $superclass:ty; + type Kind = $kind:ty; + const NAME: &'static str = $name_const:literal; } @@ -428,6 +434,8 @@ macro_rules! declare_class { $(#[inherits($($inheritance_rest),+)])? type Super = $superclass; + type Kind = $kind; + const NAME: &'static str = $name_const; } @@ -444,6 +452,8 @@ macro_rules! declare_class { $(#[inherits($($inheritance_rest:ty),+)])? type Super = $superclass:ty; + type Kind = $kind:ty; + const NAME: &'static str = $name_const:literal; } @@ -468,6 +478,8 @@ macro_rules! declare_class { $(#[inherits($($inheritance_rest),+)])? type Super = $superclass; + type Kind = $kind; + const NAME: &'static str = $name_const; } @@ -486,6 +498,8 @@ macro_rules! __inner_declare_class { $(#[inherits($($inheritance_rest:ty),+)])? type Super = $superclass:ty; + type Kind = $kind:ty; + const NAME: &'static str = $name_const:literal; } @@ -501,6 +515,9 @@ macro_rules! __inner_declare_class { // Creation unsafe impl ClassType for $for { type Super = $superclass; + + type Kind = $kind; + const NAME: &'static $crate::__macro_helpers::str = $name_const; fn class() -> &'static $crate::runtime::Class { diff --git a/crates/objc2/src/macros/extern_class.rs b/crates/objc2/src/macros/extern_class.rs index 6e7f39bf5..9c22773d8 100644 --- a/crates/objc2/src/macros/extern_class.rs +++ b/crates/objc2/src/macros/extern_class.rs @@ -63,9 +63,10 @@ /// Create a new type to represent the `NSFormatter` class. /// /// ``` -/// use objc2::runtime::NSObject; +/// use objc2::class::{ClassType, Unknown}; /// use objc2::rc::Id; -/// use objc2::{ClassType, extern_class, msg_send_id}; +/// use objc2::runtime::NSObject; +/// use objc2::{extern_class, msg_send_id}; /// /// extern_class!( /// /// An example description. @@ -76,6 +77,7 @@ /// // Specify the superclass, in this case `NSObject` /// unsafe impl ClassType for NSFormatter { /// type Super = NSObject; +/// type Kind = Unknown; /// // Optionally, specify the name of the class, if it differs from /// // the struct name. /// // const NAME: &'static str = "NSFormatter"; @@ -99,8 +101,9 @@ /// declared previously to specify as its superclass. /// /// ``` +/// use objc2::class::{ClassType, Unknown}; /// use objc2::runtime::NSObject; -/// use objc2::{extern_class, ClassType}; +/// use objc2::extern_class; /// # /// # extern_class!( /// # #[derive(PartialEq, Eq, Hash)] @@ -108,6 +111,7 @@ /// # /// # unsafe impl ClassType for NSFormatter { /// # type Super = NSObject; +/// # type Kind = Unknown; /// # } /// # ); /// @@ -119,13 +123,14 @@ /// // Specify the correct inheritance chain /// #[inherits(NSObject)] /// type Super = NSFormatter; +/// type Kind = Unknown; /// } /// ); /// /// // Similarly, we can specify the protocols that this implements here: /// // -/// // unsafe impl NSCoding for NSFormatter {} -/// // unsafe impl NSCopying for NSFormatter {} +/// // unsafe impl NSCoding for NSDateFormatter {} +/// // unsafe impl NSCopying for NSDateFormatter {} /// ``` /// /// See the source code of `icrate` for many more examples. @@ -141,6 +146,7 @@ macro_rules! extern_class { unsafe impl ClassType for $for:ty { $(#[inherits($($inheritance_rest:ty),+)])? type Super = $superclass:ty; + type Kind = $kind:ty; $(const NAME: &'static str = $name_const:literal;)? } @@ -154,6 +160,7 @@ macro_rules! extern_class { unsafe impl ClassType for $for { $(#[inherits($($inheritance_rest),+)])? type Super = $superclass; + type Kind = $kind; $(const NAME: &'static str = $name_const;)? } @@ -169,6 +176,7 @@ macro_rules! extern_class { unsafe impl ClassType for $for:ty { $(#[inherits($($inheritance_rest:ty),+)])? type Super = $superclass:ty; + type Kind = $kind:ty; $(const NAME: &'static str = $name_const:literal;)? } @@ -183,6 +191,7 @@ macro_rules! extern_class { unsafe impl<> ClassType for $for { $(#[inherits($($inheritance_rest),+)])? type Super = $superclass; + type Kind = $kind; $(const NAME: &'static str = $name_const;)? } @@ -271,6 +280,7 @@ macro_rules! __inner_extern_class { unsafe impl<$($t_for:ident $(: $b_for:ident)?),* $(,)?> ClassType for $for:ty { $(#[inherits($($inheritance_rest:ty),+ $(,)?)])? type Super = $superclass:ty; + type Kind = $kind:ty; $(const NAME: &'static str = $name_const:literal;)? } @@ -295,6 +305,7 @@ macro_rules! __inner_extern_class { $(#[$impl_m])* unsafe impl<$($t_for $(: $b_for)?),*> ClassType for $for { type Super = $superclass; + type Kind = $kind; const NAME: &'static $crate::__macro_helpers::str = $crate::__select_name!($name; $($name_const)?); #[inline] diff --git a/crates/objc2/src/macros/extern_methods.rs b/crates/objc2/src/macros/extern_methods.rs index aefd7e3df..66199ca13 100644 --- a/crates/objc2/src/macros/extern_methods.rs +++ b/crates/objc2/src/macros/extern_methods.rs @@ -58,11 +58,12 @@ /// Let's create a quick custom class: /// /// ``` +/// use objc2::class::{ClassType, Immutable}; /// use objc2::encode::{Encode, Encoding}; /// use objc2::ffi::NSUInteger; /// use objc2::rc::{Allocated, Id}; /// use objc2::runtime::NSObject; -/// use objc2::{declare_class, extern_methods, ClassType}; +/// use objc2::{declare_class, extern_methods}; /// /// // Shim /// type NSError = NSObject; @@ -72,6 +73,7 @@ /// /// unsafe impl ClassType for MyObject { /// type Super = NSObject; +/// type Kind = Immutable; /// const NAME: &'static str = "MyObject"; /// } /// diff --git a/crates/objc2/src/protocol.rs b/crates/objc2/src/protocol.rs index 028af5ab2..48be7702d 100644 --- a/crates/objc2/src/protocol.rs +++ b/crates/objc2/src/protocol.rs @@ -263,9 +263,10 @@ mod tests { use core::mem::ManuallyDrop; use super::*; + use crate::class::{ClassType, Immutable}; use crate::rc::Owned; use crate::runtime::{NSObject, NSObjectProtocol}; - use crate::{declare_class, extern_methods, extern_protocol, ClassType}; + use crate::{declare_class, extern_methods, extern_protocol}; extern_protocol!( unsafe trait Foo { @@ -321,6 +322,7 @@ mod tests { unsafe impl ClassType for DummyClass { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "ProtocolTestsDummyClass"; } ); diff --git a/crates/objc2/src/rc/test_object.rs b/crates/objc2/src/rc/test_object.rs index 5372692b4..3e87cb437 100644 --- a/crates/objc2/src/rc/test_object.rs +++ b/crates/objc2/src/rc/test_object.rs @@ -2,8 +2,9 @@ use core::cell::RefCell; use core::ptr; use super::{Allocated, Id, Owned}; +use crate::class::{ClassType, Immutable}; use crate::runtime::{NSObject, NSZone}; -use crate::{declare_class, msg_send, msg_send_id, ClassType}; +use crate::{declare_class, msg_send, msg_send_id}; // TODO: Put tests that use this in another crate #[derive(Debug, Clone, Default, PartialEq, Eq)] @@ -57,6 +58,7 @@ declare_class!( unsafe impl ClassType for __RcTestObject { type Super = NSObject; + type Kind = Immutable; const NAME: &'static str = "__RcTestObject"; } @@ -298,6 +300,7 @@ declare_class!( unsafe impl ClassType for RcTestObjectSubclass { #[inherits(NSObject)] type Super = __RcTestObject; + type Kind = Immutable; const NAME: &'static str = "RcTestObjectSubclass"; } ); diff --git a/crates/objc2/src/runtime/nsobject.rs b/crates/objc2/src/runtime/nsobject.rs index 1ea6111a4..4bee49711 100644 --- a/crates/objc2/src/runtime/nsobject.rs +++ b/crates/objc2/src/runtime/nsobject.rs @@ -1,12 +1,11 @@ use core::fmt; use core::hash; +use crate::class::{ClassType, Unknown}; +use crate::protocol::{ImplementedBy, ProtocolObject, ProtocolType}; use crate::rc::{DefaultId, Id, Owned}; use crate::runtime::{Class, Object, Protocol}; -use crate::{ - extern_methods, msg_send, msg_send_id, ClassType, ImplementedBy, Message, ProtocolObject, - ProtocolType, -}; +use crate::{extern_methods, msg_send, msg_send_id, Message}; crate::__emit_struct! { ( @@ -38,6 +37,7 @@ crate::__extern_class_impl_traits! { unsafe impl ClassType for NSObject { type Super = Object; + type Kind = Unknown; const NAME: &'static str = "NSObject"; #[inline] diff --git a/crates/objc2/tests/declare_class_self.rs b/crates/objc2/tests/declare_class_self.rs index 0104d843d..f96a98c17 100644 --- a/crates/objc2/tests/declare_class_self.rs +++ b/crates/objc2/tests/declare_class_self.rs @@ -2,9 +2,10 @@ //! and hence we _must_ implement things by changing the generated method, we //! can't just create an internal helper function (since we can't name the //! types of such a function)! +use objc2::class::{ClassType, Mutable}; +use objc2::declare_class; use objc2::rc::{Allocated, Id}; use objc2::runtime::NSObject; -use objc2::{declare_class, ClassType}; trait GetSameType { type SameType: ?Sized; @@ -25,6 +26,8 @@ declare_class!( unsafe impl ClassType for MyTestObject { type Super = NSObject; + type Kind = Mutable; + const NAME: &'static str = "MyTestObject"; } diff --git a/crates/objc2/tests/no_prelude.rs b/crates/objc2/tests/no_prelude.rs index f7b1b7fa2..76e49b859 100644 --- a/crates/objc2/tests/no_prelude.rs +++ b/crates/objc2/tests/no_prelude.rs @@ -93,6 +93,7 @@ new_objc2::declare_class!( unsafe impl ClassType for CustomObject { type Super = new_objc2::runtime::NSObject; + type Kind = new_objc2::class::Unknown; const NAME: &'static str = "CustomObject"; } @@ -127,6 +128,7 @@ new_objc2::extern_class!( unsafe impl ClassType for NSObject2 { type Super = new_objc2::runtime::NSObject; + type Kind = new_objc2::class::Unknown; const NAME: &'static str = "NSObject"; } ); diff --git a/crates/objc2/tests/track_caller.rs b/crates/objc2/tests/track_caller.rs index aacb20f71..dfe5f3fab 100644 --- a/crates/objc2/tests/track_caller.rs +++ b/crates/objc2/tests/track_caller.rs @@ -6,10 +6,11 @@ use std::process::abort; use std::ptr; use std::sync::Mutex; +use objc2::class::{ClassType, Unknown}; use objc2::encode::Encode; use objc2::rc::{Allocated, Id, __RcTestObject}; use objc2::runtime::{NSObject, Object}; -use objc2::{class, declare_class, msg_send, msg_send_id, ClassType}; +use objc2::{class, declare_class, msg_send, msg_send_id}; static EXPECTED_MESSAGE: Mutex = Mutex::new(String::new()); static EXPECTED_LINE: Mutex = Mutex::new(0); @@ -190,6 +191,7 @@ declare_class!( unsafe impl ClassType for PanickingClass { type Super = NSObject; + type Kind = Unknown; const NAME: &'static str = "PanickingClass"; }