Skip to content

Commit

Permalink
Revert "Allow msg_send_id![obj, init] to non-option wrapped Id"
Browse files Browse the repository at this point in the history
It makes error messages and documentation worse (which _is_ a big deal), and I doubt it'll really be useful. Besides, we can always re-add it without breaking changes!
  • Loading branch information
madsmtm committed Jun 15, 2022
1 parent 0e92a0a commit 195e32e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
8 changes: 3 additions & 5 deletions objc2/src/__macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
}

// `init`, should mark the input value as "allocated, not initialized" somehow
//
// The generic bound allows `init` to take both `Option<Id>` and `Id`.
impl<X: Into<Option<Id<T, O>>>, T: ?Sized + Message, O: Ownership> MsgSendId<X, Id<T, O>>
impl<T: ?Sized + Message, O: Ownership> MsgSendId<Option<Id<T, O>>, Id<T, O>>
for RetainSemantics<false, false, true, false>
{
#[inline(always)]
unsafe fn send_message_id<A: MessageArguments>(
obj: X,
obj: Option<Id<T, O>>,
sel: Sel,
args: A,
) -> Result<Option<Id<T, O>>, MessageError> {
Expand Down Expand Up @@ -242,7 +240,7 @@ mod tests {
expected.alloc += 1;
// Check allocation error before init
let obj = obj.unwrap();
let _obj: Id<RcTestObject, Shared> = unsafe { msg_send_id![obj, init].unwrap() };
let _obj: Id<RcTestObject, Shared> = unsafe { msg_send_id![Some(obj), init].unwrap() };
expected.init += 1;
expected.assert_current();
}
Expand Down
7 changes: 3 additions & 4 deletions objc2/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ macro_rules! msg_send_bool {
/// - The `alloc` family: The receiver must be `&Class`, and the return type
/// is a generic `Option<Id<T, O>>`. (This will change, see [#172]).
///
/// - The `init` family: The receiver must be either `Id<T, O>` or
/// `Option<Id<T, O>>` as returned from `alloc`. The receiver is consumed,
/// and a the now-initialized `Option<Id<T, O>>` (with the same `T` and `O`)
/// is returned.
/// - The `init` family: The receiver must be `Option<Id<T, O>>` as returned
/// from `alloc`. The receiver is consumed, and a the now-initialized
/// `Option<Id<T, O>>` (with the same `T` and `O`) is returned.
///
/// - The `copy` family: The receiver may be anything that implements
/// [`MessageReceiver`] and the return type is a generic `Option<Id<T, O>>`.
Expand Down
46 changes: 26 additions & 20 deletions tests/ui/msg_send_id_invalid_receiver.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,39 @@ note: associated function defined here
| unsafe fn send_message_id<A: MessageArguments>(
| ^^^^^^^^^^^^^^^

error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Object>` is not satisfied
--> ui/msg_send_id_invalid_receiver.rs:10:42
error[E0308]: mismatched types
--> ui/msg_send_id_invalid_receiver.rs:10:55
|
10 | let _: Id<Object, Shared> = unsafe { msg_send_id![obj, init].unwrap() };
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&objc2::runtime::Object>` is not implemented for `Option<Id<_, _>>`
| -------------^^^-------
| | |
| | expected enum `Option`, found `&objc2::runtime::Object`
| arguments to this function are incorrect
|
= help: the following other types implement trait `From<T>`:
<Option<&'a T> as From<&'a Option<T>>>
<Option<&'a mut T> as From<&'a mut Option<T>>>
<Option<T> as From<T>>
= note: required because of the requirements on the impl of `Into<Option<Id<_, _>>>` for `&objc2::runtime::Object`
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Object, Id<_, _>>` for `RetainSemantics<false, false, true, false>`
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: expected enum `Option<Id<_, _>>`
found reference `&objc2::runtime::Object`
note: associated function defined here
--> $WORKSPACE/objc2/src/__macro_helpers.rs
|
| unsafe fn send_message_id<A: MessageArguments>(
| ^^^^^^^^^^^^^^^

error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Class>` is not satisfied
--> ui/msg_send_id_invalid_receiver.rs:13:42
error[E0308]: mismatched types
--> ui/msg_send_id_invalid_receiver.rs:13:55
|
13 | let _: Id<Object, Shared> = unsafe { msg_send_id![cls, init].unwrap() };
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&objc2::runtime::Class>` is not implemented for `Option<Id<_, _>>`
| -------------^^^-------
| | |
| | expected enum `Option`, found `&objc2::runtime::Class`
| arguments to this function are incorrect
|
= help: the following other types implement trait `From<T>`:
<Option<&'a T> as From<&'a Option<T>>>
<Option<&'a mut T> as From<&'a mut Option<T>>>
<Option<T> as From<T>>
= note: required because of the requirements on the impl of `Into<Option<Id<_, _>>>` for `&objc2::runtime::Class`
= note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Id<_, _>>` for `RetainSemantics<false, false, true, false>`
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: expected enum `Option<Id<_, _>>`
found reference `&objc2::runtime::Class`
note: associated function defined here
--> $WORKSPACE/objc2/src/__macro_helpers.rs
|
| unsafe fn send_message_id<A: MessageArguments>(
| ^^^^^^^^^^^^^^^

error[E0277]: the trait bound `Id<objc2::runtime::Object, Shared>: MessageReceiver` is not satisfied
--> ui/msg_send_id_invalid_receiver.rs:16:42
Expand Down

0 comments on commit 195e32e

Please sign in to comment.