Skip to content

Commit f0211c2

Browse files
committed
Fix UnwindSafe/Send/Sync impls for upcoming changes to the compiler
See rust-lang/rust#93367
1 parent a10fec8 commit f0211c2

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

objc2-foundation/src/array.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,10 @@ unsafe impl<T: Send> Send for NSArray<T, Owned> {}
4343

4444
object! {
4545
// TODO: Ensure that this deref to NSArray is safe!
46-
unsafe pub struct NSMutableArray<T, O: Ownership>: NSArray<T, O> {
47-
item: PhantomData<Id<T, O>>,
48-
}
46+
// This "inherits" NSArray, and has the same `Send`/`Sync` impls as that.
47+
unsafe pub struct NSMutableArray<T, O: Ownership>: NSArray<T, O> {}
4948
}
5049

51-
// SAFETY: Same as NSArray.
52-
//
53-
// TODO: Properly verify this
54-
unsafe impl<T: Sync + Send> Sync for NSMutableArray<T, Shared> {}
55-
unsafe impl<T: Sync + Send> Send for NSMutableArray<T, Shared> {}
56-
unsafe impl<T: Sync> Sync for NSMutableArray<T, Owned> {}
57-
unsafe impl<T: Send> Send for NSMutableArray<T, Owned> {}
58-
5950
unsafe fn from_refs<T: Message + ?Sized>(cls: &Class, refs: &[&T]) -> NonNull<Object> {
6051
let obj: *mut Object = unsafe { msg_send![cls, alloc] };
6152
let obj: *mut Object = unsafe {

objc2/src/rc/id.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use core::fmt;
22
use core::marker::PhantomData;
33
use core::mem::ManuallyDrop;
44
use core::ops::{Deref, DerefMut};
5+
use core::panic::{RefUnwindSafe, UnwindSafe};
56
use core::ptr::NonNull;
6-
use std::panic::{RefUnwindSafe, UnwindSafe};
77

88
use super::AutoreleasePool;
99
use super::{Owned, Ownership, Shared};
@@ -117,6 +117,11 @@ pub struct Id<T: ?Sized, O: Ownership> {
117117
item: PhantomData<T>,
118118
/// To prevent warnings about unused type parameters.
119119
own: PhantomData<O>,
120+
/// Marks the type as !UnwindSafe. Later on we'll re-enable this.
121+
///
122+
/// See <https://github.com/rust-lang/rust/issues/93367> for why this is
123+
/// required.
124+
notunwindsafe: PhantomData<&'static mut ()>,
120125
}
121126

122127
impl<T: Message + ?Sized, O: Ownership> Id<T, O> {
@@ -171,6 +176,7 @@ impl<T: Message + ?Sized, O: Ownership> Id<T, O> {
171176
ptr,
172177
item: PhantomData,
173178
own: PhantomData,
179+
notunwindsafe: PhantomData,
174180
}
175181
}
176182

0 commit comments

Comments
 (0)