-
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.
Test that msg_send! consumes the receiver
- Loading branch information
Showing
4 changed files
with
60 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//! Test that `msg_send!` consumes their arguments, including the receiver. | ||
//! | ||
//! Ideally, it shouldn't be so, but that's how it works currently. | ||
use objc2::{msg_send, class}; | ||
use objc2::runtime::Object; | ||
|
||
fn main() { | ||
let cls = class!(NSObject); | ||
let obj: &mut Object = unsafe { msg_send![cls, new] }; | ||
|
||
let _: () = unsafe { msg_send![obj, selector] }; | ||
// Could be solved with a reborrow | ||
let _: () = unsafe { msg_send![obj, selector] }; | ||
} |
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,17 @@ | ||
error[E0382]: use of moved value: `obj` | ||
--> ui/msg_send_mutable.rs:13:36 | ||
| | ||
9 | let obj: &mut Object = unsafe { msg_send![cls, new] }; | ||
| --- move occurs because `obj` has type `&mut objc2::runtime::Object`, which does not implement the `Copy` trait | ||
10 | | ||
11 | let _: () = unsafe { msg_send![obj, selector] }; | ||
| ------------------------ `obj` moved due to this method call | ||
12 | // Could be solved with a reborrow | ||
13 | let _: () = unsafe { msg_send![obj, selector] }; | ||
| ^^^ value used here after move | ||
| | ||
note: this function takes ownership of the receiver `self`, which moves `obj` | ||
--> $WORKSPACE/objc2/src/message/mod.rs | ||
| | ||
| unsafe fn send_message<A, R>(self, sel: Sel, args: A) -> Result<R, MessageError> | ||
| ^^^^ |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
//! Test that return types that are not `Encode` are not accepted. | ||
//! Test that types that are not `Encode` are not accepted. | ||
use objc2::{class, msg_send}; | ||
|
||
fn main() { | ||
let cls = class!(NSData); | ||
unsafe { | ||
let cls = class!(NSData); | ||
let _: Vec<u8> = msg_send![cls, new]; | ||
|
||
let x: Vec<u8>; | ||
let _: () = msg_send![cls, newWith: x]; | ||
} | ||
} |
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