From 726c6606fb511d8125f433c0b5eddb2e456673b7 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 15 Jun 2022 22:34:55 +0200 Subject: [PATCH] Revert "Allow msg_send_id![obj, init] to non-option wrapped Id" 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! --- objc2/src/__macro_helpers.rs | 10 ++--- objc2/src/macros.rs | 7 ++- tests/ui/msg_send_id_invalid_receiver.stderr | 46 +++++++++++--------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/objc2/src/__macro_helpers.rs b/objc2/src/__macro_helpers.rs index 1ef6df989..e8a25c457 100644 --- a/objc2/src/__macro_helpers.rs +++ b/objc2/src/__macro_helpers.rs @@ -78,18 +78,16 @@ impl MsgSendId<&'_ Class, Id> } // `init`, should mark the input value as "allocated, not initialized" somehow -// -// The generic bound allows `init` to take both `Option` and `Id`. -impl>>, T: ?Sized + Message, O: Ownership> MsgSendId> +impl MsgSendId>, Id> for RetainSemantics { #[inline(always)] unsafe fn send_message_id( - obj: X, + obj: Option>, sel: Sel, args: A, ) -> Result>, MessageError> { - let ptr = Id::option_into_ptr(obj.into()); + let ptr = Id::option_into_ptr(obj); // SAFETY: `ptr` may be null here, but that's fine since the return // is `*mut T`, which is one of the few types where messages to nil is // allowed. @@ -242,7 +240,7 @@ mod tests { expected.alloc += 1; // Check allocation error before init let obj = obj.unwrap(); - let _obj: Id = unsafe { msg_send_id![obj, init].unwrap() }; + let _obj: Id = unsafe { msg_send_id![Some(obj), init].unwrap() }; expected.init += 1; expected.assert_current(); } diff --git a/objc2/src/macros.rs b/objc2/src/macros.rs index 9aaa25a5b..86509da17 100644 --- a/objc2/src/macros.rs +++ b/objc2/src/macros.rs @@ -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>`. (This will change, see [#172]). /// -/// - The `init` family: The receiver must be either `Id` or -/// `Option>` as returned from `alloc`. The receiver is consumed, -/// and a the now-initialized `Option>` (with the same `T` and `O`) -/// is returned. +/// - The `init` family: The receiver must be `Option>` as returned +/// from `alloc`. The receiver is consumed, and a the now-initialized +/// `Option>` (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>`. diff --git a/tests/ui/msg_send_id_invalid_receiver.stderr b/tests/ui/msg_send_id_invalid_receiver.stderr index 386b245d5..b20d72a68 100644 --- a/tests/ui/msg_send_id_invalid_receiver.stderr +++ b/tests/ui/msg_send_id_invalid_receiver.stderr @@ -32,33 +32,39 @@ note: associated function defined here | unsafe fn send_message_id( | ^^^^^^^^^^^^^^^ -error[E0277]: the trait bound `Option>: 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 = unsafe { msg_send_id![obj, init].unwrap() }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&objc2::runtime::Object>` is not implemented for `Option>` + | -------------^^^------- + | | | + | | expected enum `Option`, found `&objc2::runtime::Object` + | arguments to this function are incorrect | - = help: the following other types implement trait `From`: - as From<&'a Option>> - as From<&'a mut Option>> - as From> - = note: required because of the requirements on the impl of `Into>>` for `&objc2::runtime::Object` - = note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Object, Id<_, _>>` for `RetainSemantics` - = 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>` + found reference `&objc2::runtime::Object` +note: associated function defined here + --> $WORKSPACE/objc2/src/__macro_helpers.rs + | + | unsafe fn send_message_id( + | ^^^^^^^^^^^^^^^ -error[E0277]: the trait bound `Option>: 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 = unsafe { msg_send_id![cls, init].unwrap() }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&objc2::runtime::Class>` is not implemented for `Option>` + | -------------^^^------- + | | | + | | expected enum `Option`, found `&objc2::runtime::Class` + | arguments to this function are incorrect | - = help: the following other types implement trait `From`: - as From<&'a Option>> - as From<&'a mut Option>> - as From> - = note: required because of the requirements on the impl of `Into>>` for `&objc2::runtime::Class` - = note: required because of the requirements on the impl of `MsgSendId<&objc2::runtime::Class, Id<_, _>>` for `RetainSemantics` - = 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>` + found reference `&objc2::runtime::Class` +note: associated function defined here + --> $WORKSPACE/objc2/src/__macro_helpers.rs + | + | unsafe fn send_message_id( + | ^^^^^^^^^^^^^^^ error[E0277]: the trait bound `Id: MessageReceiver` is not satisfied --> ui/msg_send_id_invalid_receiver.rs:16:42