-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax ProtocolType requirement on ProtocolObject
This allows us to do `ProtocolObject<dyn ProtocolA + ProtocolB>` in the future.
- Loading branch information
Showing
6 changed files
with
274 additions
and
33 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,27 @@ | ||
//! Ensure that `ProtocolObject` cannot be incorrectly constructed. | ||
use icrate::Foundation::NSCopying; | ||
use objc2::runtime::{NSObject, NSObjectProtocol, ProtocolObject}; | ||
|
||
trait Foo { | ||
fn foo(&self) {} | ||
} | ||
|
||
impl<T: ?Sized> Foo for T {} | ||
|
||
fn main() { | ||
let obj = NSObject::new(); | ||
let _: &ProtocolObject<NSObject> = ProtocolObject::from_ref(&*obj); | ||
let _: &ProtocolObject<dyn Send> = ProtocolObject::from_ref(&*obj); | ||
let _: &ProtocolObject<dyn Foo> = ProtocolObject::from_ref(&*obj); | ||
|
||
// `NSObject` is neither `Send` nor `Sync`. | ||
let _: &ProtocolObject<dyn NSObjectProtocol + Send> = ProtocolObject::from_ref(&*obj); | ||
let _: &ProtocolObject<dyn NSObjectProtocol + Sync> = ProtocolObject::from_ref(&*obj); | ||
let _: &ProtocolObject<dyn NSObjectProtocol + Send + Sync> = ProtocolObject::from_ref(&*obj); | ||
|
||
// `NSObject` is not `NSCopying`. | ||
let _: &ProtocolObject<dyn NSCopying> = ProtocolObject::from_ref(&*obj); | ||
|
||
// `dyn NSCopying + Send` does not implement `ImplementedBy` (yet). | ||
let _: &ProtocolObject<dyn NSCopying + Send> = ProtocolObject::from_ref(&*obj); | ||
} |
Oops, something went wrong.