Skip to content

Commit

Permalink
Remove ability to send messages to Option types
Browse files Browse the repository at this point in the history
We actually don't want to encourage sending messages to nil objects, since that is only supported for selectors that return pointers
  • Loading branch information
madsmtm committed Oct 3, 2021
1 parent 4cabdb9 commit 1b62354
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions objc2/src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloc::string::{String, ToString};
use core::fmt;
use core::mem;
use core::ptr;
use core::ptr::NonNull;
use std::error::Error;

Expand Down Expand Up @@ -78,11 +77,6 @@ pub(crate) mod private {
impl<'a, T: Message + ?Sized> Sealed for &'a mut T {}
impl<T: Message + ?Sized> Sealed for NonNull<T> {}
impl<T: Message, O: Ownership> Sealed for Id<T, O> {}

impl<'a, T: Message + ?Sized> Sealed for Option<&'a T> {}
impl<'a, T: Message + ?Sized> Sealed for Option<&'a mut T> {}
impl<T: Message + ?Sized> Sealed for Option<NonNull<T>> {}
impl<T: Message, O: Ownership> Sealed for Option<Id<T, O>> {}
}

/// Types that can directly be used as the receiver of Objective-C messages.
Expand Down Expand Up @@ -239,46 +233,6 @@ unsafe impl<T: Message, O: Ownership> MessageReceiver for Id<T, O> {
}
}

unsafe impl<'a, T: Message + ?Sized> MessageReceiver for Option<&'a T> {
#[inline]
fn as_raw_receiver(&self) -> *mut Object {
match self {
None => ptr::null_mut(),
Some(obj) => obj.as_raw_receiver(),
}
}
}

unsafe impl<'a, T: Message + ?Sized> MessageReceiver for Option<&'a mut T> {
#[inline]
fn as_raw_receiver(&self) -> *mut Object {
match self {
None => ptr::null_mut(),
Some(obj) => obj.as_raw_receiver(),
}
}
}

unsafe impl<T: Message + ?Sized> MessageReceiver for Option<NonNull<T>> {
#[inline]
fn as_raw_receiver(&self) -> *mut Object {
match self {
None => ptr::null_mut(),
Some(obj) => obj.as_raw_receiver(),
}
}
}

unsafe impl<T: Message, O: Ownership> MessageReceiver for Option<Id<T, O>> {
#[inline]
fn as_raw_receiver(&self) -> *mut Object {
match self {
None => ptr::null_mut(),
Some(id) => id.as_raw_receiver(),
}
}
}

/// Types that may be used as the arguments of an Objective-C message.
pub trait MessageArguments: EncodeArguments {
/// Invoke an [`Imp`] with the given object, selector, and arguments.
Expand Down

0 comments on commit 1b62354

Please sign in to comment.