Skip to content

Commit aed5cdd

Browse files
committed
Improve msg_send_id! macro diagnostics a bit more
1 parent d635b89 commit aed5cdd

File tree

6 files changed

+17
-24
lines changed

6 files changed

+17
-24
lines changed

objc2/src/__macro_helpers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub trait MsgSendId<T, U> {
2020
obj: T,
2121
sel: Sel,
2222
args: A,
23-
) -> Result<U, MessageError>;
23+
) -> Result<Option<U>, MessageError>;
2424
}
2525

2626
// `new`
27-
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Option<Id<T, O>>>
27+
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
2828
for Assert<true, false, false, false>
2929
{
3030
#[inline(always)]
@@ -38,7 +38,7 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Option<Id<T, O>>>
3838
}
3939

4040
// `alloc`, should mark the return value as "allocated, not initialized" somehow
41-
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Option<Id<T, O>>>
41+
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
4242
for Assert<false, true, false, false>
4343
{
4444
#[inline(always)]
@@ -54,7 +54,7 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Option<Id<T, O>>>
5454
// `init`, should mark the input value as "allocated, not initialized" somehow
5555
//
5656
// The generic bound allows `init` to take both `Option<Id>` and `Id`.
57-
impl<X: Into<Option<Id<T, O>>>, T: ?Sized + Message, O: Ownership> MsgSendId<X, Option<Id<T, O>>>
57+
impl<X: Into<Option<Id<T, O>>>, T: ?Sized + Message, O: Ownership> MsgSendId<X, Id<T, O>>
5858
for Assert<false, false, true, false>
5959
{
6060
#[inline(always)]
@@ -75,7 +75,7 @@ impl<X: Into<Option<Id<T, O>>>, T: ?Sized + Message, O: Ownership> MsgSendId<X,
7575
}
7676

7777
// `copy` and `mutableCopy`
78-
impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendId<T, Option<Id<U, O>>>
78+
impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendId<T, Id<U, O>>
7979
for Assert<false, false, false, true>
8080
{
8181
#[inline(always)]
@@ -89,7 +89,7 @@ impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendId<T, Option<
8989
}
9090

9191
// All other selectors
92-
impl<T: MessageReceiver, U: Message, O: Ownership> MsgSendId<T, Option<Id<U, O>>>
92+
impl<T: MessageReceiver, U: Message, O: Ownership> MsgSendId<T, Id<U, O>>
9393
for Assert<false, false, false, false>
9494
{
9595
#[inline(always)]

objc2/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ macro_rules! msg_send_id {
258258
let sel = $crate::sel!($selector);
259259
const NAME: &[u8] = stringify!($selector).as_bytes();
260260
$crate::msg_send_id!(@__get_assert_consts NAME);
261-
let result;
261+
let result: Option<$crate::rc::Id<_, _>>;
262262
match <X as $crate::__macro_helpers::MsgSendId<_, _>>::send_message_id($obj, sel, ()) {
263263
Err(s) => panic!("{}", s),
264264
Ok(r) => result = r,
@@ -269,7 +269,7 @@ macro_rules! msg_send_id {
269269
let sel = $crate::sel!($($selector:)+);
270270
const NAME: &[u8] = concat!($(stringify!($selector), ':'),+).as_bytes();
271271
$crate::msg_send_id!(@__get_assert_consts NAME);
272-
let result;
272+
let result: Option<$crate::rc::Id<_, _>>;
273273
match <X as $crate::__macro_helpers::MsgSendId<_, _>>::send_message_id($obj, sel, ($($argument,)+)) {
274274
Err(s) => panic!("{}", s),
275275
Ok(r) => result = r,

tests/ui/msg_send_id_invalid_receiver.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Object>`
4343
<Option<&'a mut T> as From<&'a mut Option<T>>>
4444
<Option<T> as From<T>>
4545
= note: required because of the requirements on the impl of `Into<Option<Id<_, _>>>` for `&objc2::runtime::Object`
46-
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Object, Option<Id<_, _>>>` for `Assert<false, false, true, false>`
46+
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Object, Id<_, _>>` for `Assert<false, false, true, false>`
4747
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
4848

4949
error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Class>` is not satisfied
@@ -57,7 +57,7 @@ error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Class>` i
5757
<Option<&'a mut T> as From<&'a mut Option<T>>>
5858
<Option<T> as From<T>>
5959
= note: required because of the requirements on the impl of `Into<Option<Id<_, _>>>` for `&objc2::runtime::Class`
60-
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Option<Id<_, _>>>` for `Assert<false, false, true, false>`
60+
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Id<_, _>>` for `Assert<false, false, true, false>`
6161
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
6262

6363
error[E0277]: the trait bound `Id<objc2::runtime::Object, Shared>: MessageReceiver` is not satisfied
@@ -69,5 +69,5 @@ error[E0277]: the trait bound `Id<objc2::runtime::Object, Shared>: MessageReceiv
6969
= help: the following other types implement trait `MessageReceiver`:
7070
&'a Id<T, O>
7171
&'a mut Id<T, objc2::rc::Owned>
72-
= note: required because of the requirements on the impl of `MsgSendId<Id<objc2::runtime::Object, Shared>, Option<Id<_, _>>>` for `Assert<false, false, false, true>`
72+
= note: required because of the requirements on the impl of `MsgSendId<Id<objc2::runtime::Object, Shared>, Id<_, _>>` for `Assert<false, false, false, true>`
7373
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/ui/msg_send_id_invalid_return.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ error[E0277]: the trait bound `objc2::runtime::Class: Message` is not satisfied
2626
NSMutableData
2727
NSMutableString
2828
and 7 others
29-
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Option<Id<objc2::runtime::Class, Shared>>>` for `Assert<true, false, false, false>`
29+
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Id<objc2::runtime::Class, Shared>>` for `Assert<true, false, false, false>`
3030
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error[E0308]: mismatched types
@@ -57,7 +57,7 @@ error[E0277]: the trait bound `objc2::runtime::Class: Message` is not satisfied
5757
NSMutableData
5858
NSMutableString
5959
and 7 others
60-
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Option<Id<objc2::runtime::Class, Shared>>>` for `Assert<false, true, false, false>`
60+
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Id<objc2::runtime::Class, Shared>>` for `Assert<false, true, false, false>`
6161
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
6262

6363
error[E0308]: mismatched types

tests/ui/msg_send_id_underspecified.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Test compiler output of msg_send_id when ownership is not specified.
2-
//!
3-
//! Don't think it's really possible for us to improve this diagnostic?
42
use objc2::msg_send_id;
53
use objc2::runtime::Object;
64

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
error[E0282]: type annotations needed for `Option<Id<objc2::runtime::Object, O>>`
2-
--> ui/msg_send_id_underspecified.rs:9:33
1+
error[E0282]: type annotations needed
2+
--> ui/msg_send_id_underspecified.rs:7:33
33
|
4-
9 | let _: &Object = &*unsafe { msg_send_id![obj, description].unwrap() };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
7 | let _: &Object = &*unsafe { msg_send_id![obj, description].unwrap() };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
66
|
77
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
8-
help: consider giving `result` an explicit type, where the type for type parameter `O` is specified
9-
--> $WORKSPACE/objc2/src/macros.rs
10-
|
11-
| let result: Option<Id<objc2::runtime::Object, O>>;
12-
| +++++++++++++++++++++++++++++++++++++++

0 commit comments

Comments
 (0)