Skip to content

Commit 726c660

Browse files
committed
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!
1 parent 0e92a0a commit 726c660

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

objc2/src/__macro_helpers.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,16 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
7878
}
7979

8080
// `init`, should mark the input value as "allocated, not initialized" somehow
81-
//
82-
// The generic bound allows `init` to take both `Option<Id>` and `Id`.
83-
impl<X: Into<Option<Id<T, O>>>, T: ?Sized + Message, O: Ownership> MsgSendId<X, Id<T, O>>
81+
impl<T: ?Sized + Message, O: Ownership> MsgSendId<Option<Id<T, O>>, Id<T, O>>
8482
for RetainSemantics<false, false, true, false>
8583
{
8684
#[inline(always)]
8785
unsafe fn send_message_id<A: MessageArguments>(
88-
obj: X,
86+
obj: Option<Id<T, O>>,
8987
sel: Sel,
9088
args: A,
9189
) -> Result<Option<Id<T, O>>, MessageError> {
92-
let ptr = Id::option_into_ptr(obj.into());
90+
let ptr = Id::option_into_ptr(obj);
9391
// SAFETY: `ptr` may be null here, but that's fine since the return
9492
// is `*mut T`, which is one of the few types where messages to nil is
9593
// allowed.
@@ -242,7 +240,7 @@ mod tests {
242240
expected.alloc += 1;
243241
// Check allocation error before init
244242
let obj = obj.unwrap();
245-
let _obj: Id<RcTestObject, Shared> = unsafe { msg_send_id![obj, init].unwrap() };
243+
let _obj: Id<RcTestObject, Shared> = unsafe { msg_send_id![Some(obj), init].unwrap() };
246244
expected.init += 1;
247245
expected.assert_current();
248246
}

objc2/src/macros.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,9 @@ macro_rules! msg_send_bool {
325325
/// - The `alloc` family: The receiver must be `&Class`, and the return type
326326
/// is a generic `Option<Id<T, O>>`. (This will change, see [#172]).
327327
///
328-
/// - The `init` family: The receiver must be either `Id<T, O>` or
329-
/// `Option<Id<T, O>>` as returned from `alloc`. The receiver is consumed,
330-
/// and a the now-initialized `Option<Id<T, O>>` (with the same `T` and `O`)
331-
/// is returned.
328+
/// - The `init` family: The receiver must be `Option<Id<T, O>>` as returned
329+
/// from `alloc`. The receiver is consumed, and a the now-initialized
330+
/// `Option<Id<T, O>>` (with the same `T` and `O`) is returned.
332331
///
333332
/// - The `copy` family: The receiver may be anything that implements
334333
/// [`MessageReceiver`] and the return type is a generic `Option<Id<T, O>>`.

tests/ui/msg_send_id_invalid_receiver.stderr

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,39 @@ note: associated function defined here
3232
| unsafe fn send_message_id<A: MessageArguments>(
3333
| ^^^^^^^^^^^^^^^
3434

35-
error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Object>` is not satisfied
36-
--> ui/msg_send_id_invalid_receiver.rs:10:42
35+
error[E0308]: mismatched types
36+
--> ui/msg_send_id_invalid_receiver.rs:10:55
3737
|
3838
10 | let _: Id<Object, Shared> = unsafe { msg_send_id![obj, init].unwrap() };
39-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&objc2::runtime::Object>` is not implemented for `Option<Id<_, _>>`
39+
| -------------^^^-------
40+
| | |
41+
| | expected enum `Option`, found `&objc2::runtime::Object`
42+
| arguments to this function are incorrect
4043
|
41-
= help: the following other types implement trait `From<T>`:
42-
<Option<&'a T> as From<&'a Option<T>>>
43-
<Option<&'a mut T> as From<&'a mut Option<T>>>
44-
<Option<T> as From<T>>
45-
= 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, Id<_, _>>` for `RetainSemantics<false, false, true, false>`
47-
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
44+
= note: expected enum `Option<Id<_, _>>`
45+
found reference `&objc2::runtime::Object`
46+
note: associated function defined here
47+
--> $WORKSPACE/objc2/src/__macro_helpers.rs
48+
|
49+
| unsafe fn send_message_id<A: MessageArguments>(
50+
| ^^^^^^^^^^^^^^^
4851

49-
error[E0277]: the trait bound `Option<Id<_, _>>: From<&objc2::runtime::Class>` is not satisfied
50-
--> ui/msg_send_id_invalid_receiver.rs:13:42
52+
error[E0308]: mismatched types
53+
--> ui/msg_send_id_invalid_receiver.rs:13:55
5154
|
5255
13 | let _: Id<Object, Shared> = unsafe { msg_send_id![cls, init].unwrap() };
53-
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&objc2::runtime::Class>` is not implemented for `Option<Id<_, _>>`
56+
| -------------^^^-------
57+
| | |
58+
| | expected enum `Option`, found `&objc2::runtime::Class`
59+
| arguments to this function are incorrect
5460
|
55-
= help: the following other types implement trait `From<T>`:
56-
<Option<&'a T> as From<&'a Option<T>>>
57-
<Option<&'a mut T> as From<&'a mut Option<T>>>
58-
<Option<T> as From<T>>
59-
= 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, Id<_, _>>` for `RetainSemantics<false, false, true, false>`
61-
= note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info)
61+
= note: expected enum `Option<Id<_, _>>`
62+
found reference `&objc2::runtime::Class`
63+
note: associated function defined here
64+
--> $WORKSPACE/objc2/src/__macro_helpers.rs
65+
|
66+
| unsafe fn send_message_id<A: MessageArguments>(
67+
| ^^^^^^^^^^^^^^^
6268

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

0 commit comments

Comments
 (0)