-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify class mutability in extern_class! and declare_class!
- Loading branch information
Showing
10 changed files
with
384 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use core::ops::{Deref, DerefMut}; | ||
|
||
use objc2::encode::{Encoding, RefEncode}; | ||
use objc2::runtime::Object; | ||
use objc2::{extern_class, mutability, ClassType, Message}; | ||
|
||
#[repr(transparent)] | ||
struct MyObject(Object); | ||
|
||
unsafe impl RefEncode for MyObject { | ||
const ENCODING_REF: Encoding = Encoding::Object; | ||
} | ||
|
||
unsafe impl Message for MyObject {} | ||
|
||
impl Deref for MyObject { | ||
type Target = Object; | ||
|
||
fn deref(&self) -> &Object { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl DerefMut for MyObject { | ||
fn deref_mut(&mut self) -> &mut Object { | ||
&mut self.0 | ||
} | ||
} | ||
|
||
extern_class!( | ||
pub struct MyRootClass; | ||
|
||
unsafe impl ClassType for MyRootClass { | ||
type Super = MyObject; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0277]: the trait bound `MyObject: ClassType` is not satisfied | ||
--> ui/extern_class_root.rs | ||
| | ||
| / extern_class!( | ||
| | pub struct MyRootClass; | ||
| | | ||
| | unsafe impl ClassType for MyRootClass { | ||
... | | ||
| | } | ||
| | ); | ||
| |_^ the trait `ClassType` is not implemented for `MyObject` | ||
| | ||
= help: the following other types implement trait `ClassType`: | ||
MyRootClass | ||
NSObject | ||
__NSProxy | ||
__RcTestObject | ||
= note: this error originates in the macro `$crate::__inner_extern_class` which comes from the expansion of the macro `extern_class` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use objc2::runtime::Object; | ||
use objc2::{extern_class, mutability, ClassType}; | ||
|
||
extern_class!( | ||
pub struct MyRootClass; | ||
|
||
unsafe impl ClassType for MyRootClass { | ||
type Super = Object; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
error[E0119]: conflicting implementations of trait `AsRef<objc2::runtime::Object>` for type `MyRootClass` | ||
--> ui/extern_class_subclass_object.rs | ||
| | ||
| / extern_class!( | ||
| | pub struct MyRootClass; | ||
| | | ||
| | unsafe impl ClassType for MyRootClass { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_first implementation here | ||
| conflicting implementation for `MyRootClass` | ||
| | ||
= note: this error originates in the macro `$crate::__impl_as_ref_borrow` which comes from the expansion of the macro `extern_class` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `AsMut<objc2::runtime::Object>` for type `MyRootClass` | ||
--> ui/extern_class_subclass_object.rs | ||
| | ||
| / extern_class!( | ||
| | pub struct MyRootClass; | ||
| | | ||
| | unsafe impl ClassType for MyRootClass { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_first implementation here | ||
| conflicting implementation for `MyRootClass` | ||
| | ||
= note: this error originates in the macro `$crate::__impl_as_ref_borrow` which comes from the expansion of the macro `extern_class` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `Borrow<objc2::runtime::Object>` for type `MyRootClass` | ||
--> ui/extern_class_subclass_object.rs | ||
| | ||
| / extern_class!( | ||
| | pub struct MyRootClass; | ||
| | | ||
| | unsafe impl ClassType for MyRootClass { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_first implementation here | ||
| conflicting implementation for `MyRootClass` | ||
| | ||
= note: this error originates in the macro `$crate::__impl_as_ref_borrow` which comes from the expansion of the macro `extern_class` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `BorrowMut<objc2::runtime::Object>` for type `MyRootClass` | ||
--> ui/extern_class_subclass_object.rs | ||
| | ||
| / extern_class!( | ||
| | pub struct MyRootClass; | ||
| | | ||
| | unsafe impl ClassType for MyRootClass { | ||
... | | ||
| | } | ||
| | ); | ||
| | ^ | ||
| | | | ||
| |_first implementation here | ||
| conflicting implementation for `MyRootClass` | ||
| | ||
= note: this error originates in the macro `$crate::__impl_as_ref_borrow` which comes from the expansion of the macro `extern_class` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use objc2::runtime::NSObject; | ||
use objc2::{extern_class, mutability, ClassType}; | ||
|
||
extern_class!( | ||
pub struct MyMainThreadClass; | ||
|
||
unsafe impl ClassType for MyMainThreadClass { | ||
type Super = NSObject; | ||
type Mutability = mutability::MainThreadOnly; | ||
} | ||
); | ||
|
||
extern_class!( | ||
pub struct MyAnyThreadClass; | ||
|
||
unsafe impl ClassType for MyAnyThreadClass { | ||
type Super = MyMainThreadClass; | ||
type Mutability = mutability::InteriorMutable; | ||
} | ||
); | ||
|
||
extern_class!( | ||
pub struct MyImmutableClass1; | ||
|
||
unsafe impl ClassType for MyImmutableClass1 { | ||
type Super = NSObject; | ||
type Mutability = mutability::ImmutableWithMutableSubclass<MyMutableClass1>; | ||
} | ||
); | ||
|
||
extern_class!( | ||
pub struct MyMutableClass1; | ||
|
||
unsafe impl ClassType for MyMutableClass1 { | ||
type Super = MyImmutableClass1; | ||
type Mutability = mutability::MutableWithImmutableSuperclass<NSObject>; | ||
} | ||
); | ||
|
||
extern_class!( | ||
pub struct MyImmutableClass2; | ||
|
||
unsafe impl ClassType for MyImmutableClass2 { | ||
type Super = NSObject; | ||
type Mutability = mutability::ImmutableWithMutableSubclass<NSObject>; | ||
} | ||
); | ||
|
||
extern_class!( | ||
pub struct MyMutableClass2; | ||
|
||
unsafe impl ClassType for MyMutableClass2 { | ||
type Super = MyImmutableClass2; | ||
type Mutability = mutability::MutableWithImmutableSuperclass<MyImmutableClass2>; | ||
} | ||
); | ||
|
||
fn main() {} |
Oops, something went wrong.