Skip to content

Commit 32847a3

Browse files
committed
Add a few more encoding tests
1 parent 79e12d5 commit 32847a3

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎tests/ui/msg_send_not_encode.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Test that return types that are not `Encode` are not accepted.
2+
use objc2::{class, msg_send};
3+
4+
fn main() {
5+
unsafe {
6+
let cls = class!(NSData);
7+
let _: Vec<u8> = msg_send![cls, new];
8+
}
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the trait bound `Vec<u8>: Encode` is not satisfied
2+
--> ui/msg_send_not_encode.rs:7:26
3+
|
4+
7 | let _: Vec<u8> = msg_send![cls, new];
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Vec<u8>`
6+
|
7+
note: required by a bound in `send_message`
8+
--> $WORKSPACE/objc2/src/message/mod.rs
9+
|
10+
| R: Encode,
11+
| ^^^^^^ required by this bound in `send_message`
12+
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)

‎tests/ui/msg_send_only_message.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Test that messages can only be sent to objects.
2+
use objc2::msg_send;
3+
4+
fn main() {
5+
unsafe { msg_send![1, new] };
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0277]: the trait bound `{integer}: MessageReceiver` is not satisfied
2+
--> ui/msg_send_only_message.rs:5:14
3+
|
4+
5 | unsafe { msg_send![1, new] };
5+
| ^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `{integer}`
6+
|
7+
= help: the following implementations were found:
8+
<&'a T as MessageReceiver>
9+
<&'a mut T as MessageReceiver>
10+
<*const T as MessageReceiver>
11+
<*mut T as MessageReceiver>
12+
and 3 others
13+
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)