Skip to content

Commit

Permalink
Remove ProtocolObject::from_mut and AutoreleasePool::ptr_as_mut
Browse files Browse the repository at this point in the history
Part of #563
  • Loading branch information
madsmtm committed Sep 6, 2024
1 parent c4f2a48 commit c95962f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 43 deletions.
2 changes: 2 additions & 0 deletions crates/objc2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `Retained::as_mut_ptr`.
- `Retained::autorelease_mut`.
- `DeclaredClass::ivars_mut`.
- `ProtocolObject::from_mut`.
- `AutoreleasePool::ptr_as_mut`.
* **BREAKING**: Disallow `&mut` message receivers (except in the special case
when the object is `AnyObject`, for better backwards compatibility with
`objc`).
Expand Down
26 changes: 0 additions & 26 deletions crates/objc2/src/rc/autorelease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ pub struct AutoreleasePool<'pool> {
/// pub fn autorelease(self, s: String) -> &'pool str {
/// &*self.0.0.alloc(s)
/// }
///
/// pub fn autorelease_mut(self, s: String) -> &'pool mut str {
/// &mut *self.0.0.alloc(s)
/// }
/// }
///
/// pub fn autoreleasepool<F, R>(f: F) -> R
Expand Down Expand Up @@ -204,8 +200,6 @@ impl<'pool> AutoreleasePool<'pool> {
/// objects, since it binds the lifetime of the reference to the pool, and
/// does some extra checks when debug assertions are enabled.
///
/// For the mutable counterpart see [`ptr_as_mut`](#method.ptr_as_mut).
///
///
/// # Safety
///
Expand All @@ -217,26 +211,6 @@ impl<'pool> AutoreleasePool<'pool> {
// SAFETY: Checked by the caller
unsafe { ptr.as_ref().unwrap_unchecked() }
}

/// Returns a unique reference to the given autoreleased pointer object.
///
/// This is the preferred way to make mutable references from autoreleased
/// objects, since it binds the lifetime of the reference to the pool, and
/// does some extra checks when debug assertions are enabled.
///
/// For the shared counterpart see [`ptr_as_ref`](#method.ptr_as_ref).
///
///
/// # Safety
///
/// This is equivalent to `&mut *ptr`, and shares the unsafety of that,
/// except the lifetime is bound to the pool instead of being unbounded.
#[inline]
pub unsafe fn ptr_as_mut<T: ?Sized>(self, ptr: *mut T) -> &'pool mut T {
self.__verify_is_inner();
// SAFETY: Checked by the caller
unsafe { ptr.as_mut().unwrap_unchecked() }
}
}

/// We use a macro here so that the documentation is included whether the
Expand Down
17 changes: 0 additions & 17 deletions crates/objc2/src/runtime/protocol_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ impl<P: ?Sized> ProtocolObject<P> {
unsafe { ptr.as_ref() }
}

/// Get a mutable type-erased reference from a type implementing a
/// protocol.
#[inline]
pub fn from_mut<T: ?Sized + Message>(obj: &mut T) -> &mut Self
where
P: ImplementedBy<T>,
{
let ptr: NonNull<T> = NonNull::from(obj);
let mut ptr: NonNull<Self> = ptr.cast();
// SAFETY: Same as `as_protocol`.
//
// Since the reference came from a mutable reference to start with,
// returning a mutable reference here is safe (the lifetime of the
// returned reference is bound to the input).
unsafe { ptr.as_mut() }
}

/// Get a type-erased object from a type implementing a protocol.
///
/// Soft-deprecated alias of [`ProtocolObject::from_retained`].
Expand Down

0 comments on commit c95962f

Please sign in to comment.