From f90605b4da45374b4349913e2453527525125239 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 28 Feb 2022 15:52:49 +0100 Subject: [PATCH] Fix Id's UnwindSafe impl for upcoming changes to the compiler See https://github.com/rust-lang/rust/issues/93367 --- objc2-foundation/src/array.rs | 13 ++----------- objc2/src/rc/id.rs | 8 +++++++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/objc2-foundation/src/array.rs b/objc2-foundation/src/array.rs index 1dba1e2a6..d84015725 100644 --- a/objc2-foundation/src/array.rs +++ b/objc2-foundation/src/array.rs @@ -43,19 +43,10 @@ unsafe impl Send for NSArray {} object! { // TODO: Ensure that this deref to NSArray is safe! - unsafe pub struct NSMutableArray: NSArray { - item: PhantomData>, - } + // This "inherits" NSArray, and has the same `Send`/`Sync` impls as that. + unsafe pub struct NSMutableArray: NSArray {} } -// SAFETY: Same as NSArray. -// -// TODO: Properly verify this -unsafe impl Sync for NSMutableArray {} -unsafe impl Send for NSMutableArray {} -unsafe impl Sync for NSMutableArray {} -unsafe impl Send for NSMutableArray {} - unsafe fn from_refs(cls: &Class, refs: &[&T]) -> NonNull { let obj: *mut Object = unsafe { msg_send![cls, alloc] }; let obj: *mut Object = unsafe { diff --git a/objc2/src/rc/id.rs b/objc2/src/rc/id.rs index 01c3c215c..79ba29cfe 100644 --- a/objc2/src/rc/id.rs +++ b/objc2/src/rc/id.rs @@ -2,8 +2,8 @@ use core::fmt; use core::marker::PhantomData; use core::mem::ManuallyDrop; use core::ops::{Deref, DerefMut}; +use core::panic::{RefUnwindSafe, UnwindSafe}; use core::ptr::NonNull; -use std::panic::{RefUnwindSafe, UnwindSafe}; use super::AutoreleasePool; use super::{Owned, Ownership, Shared}; @@ -117,6 +117,11 @@ pub struct Id { item: PhantomData, /// To prevent warnings about unused type parameters. own: PhantomData, + /// Marks the type as !UnwindSafe. Later on we'll re-enable this. + /// + /// See for why this is + /// required. + notunwindsafe: PhantomData<&'static mut ()>, } impl Id { @@ -171,6 +176,7 @@ impl Id { ptr, item: PhantomData, own: PhantomData, + notunwindsafe: PhantomData, } }