Skip to content

Commit

Permalink
Add a few more encoding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 16, 2022
1 parent 79e12d5 commit 32847a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/ui/msg_send_not_encode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Test that return types that are not `Encode` are not accepted.
use objc2::{class, msg_send};

fn main() {
unsafe {
let cls = class!(NSData);
let _: Vec<u8> = msg_send![cls, new];
}
}
12 changes: 12 additions & 0 deletions tests/ui/msg_send_not_encode.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0277]: the trait bound `Vec<u8>: Encode` is not satisfied
--> ui/msg_send_not_encode.rs:7:26
|
7 | let _: Vec<u8> = msg_send![cls, new];
| ^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Vec<u8>`
|
note: required by a bound in `send_message`
--> $WORKSPACE/objc2/src/message/mod.rs
|
| R: Encode,
| ^^^^^^ required by this bound in `send_message`
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 6 additions & 0 deletions tests/ui/msg_send_only_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Test that messages can only be sent to objects.
use objc2::msg_send;

fn main() {
unsafe { msg_send![1, new] };
}
13 changes: 13 additions & 0 deletions tests/ui/msg_send_only_message.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0277]: the trait bound `{integer}: MessageReceiver` is not satisfied
--> ui/msg_send_only_message.rs:5:14
|
5 | unsafe { msg_send![1, new] };
| ^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `{integer}`
|
= help: the following implementations were found:
<&'a T as MessageReceiver>
<&'a mut T as MessageReceiver>
<*const T as MessageReceiver>
<*mut T as MessageReceiver>
and 3 others
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 32847a3

Please sign in to comment.