Skip to content

Commit b9d0d9a

Browse files
committed
Rename AllocAnyThread to AnyThread
UI tests unfortunately still seem to prefer AllocAnyThread, but that should change once we fully remove it.
1 parent f0b5884 commit b9d0d9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+117
-115
lines changed

crates/objc2/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1212
same library possible.
1313
* Added conversion trait impls from `ProtocolObject<P>` to `AnyObject`.
1414

15+
## Changed
16+
* Renamed `AllocAnyThread` to `AnyThread`. The old name is kept as deprecated.
17+
1518
## Fixed
1619
* Fixed undefined behaviour when calling `AnyObject::class` on invalid objects.
1720
* Fixed `available!` macro when running under Xcode's "Designed for iPad" setting.

crates/objc2/src/__macro_helpers/class.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{AllocAnyThread, ClassType, MainThreadOnly, ThreadKind};
1+
use crate::{AnyThread, ClassType, MainThreadOnly, ThreadKind};
22

33
/// Helper for ensuring that `ClassType::ThreadKind`, if specified, is set
44
/// correctly.
@@ -20,11 +20,11 @@ where
2020
{
2121
}
2222

23-
/// But restrict `AllocAnyThread` to only if the superclass also sets it.
24-
impl<'a, 'b, Cls> ValidThreadKind<dyn AllocAnyThread + 'a> for Cls
23+
/// But restrict `AnyThread` to only if the superclass also sets it.
24+
impl<'a, 'b, Cls> ValidThreadKind<dyn AnyThread + 'a> for Cls
2525
where
26-
Self: ClassType<ThreadKind = dyn AllocAnyThread + 'a>,
27-
Self::Super: ClassType<ThreadKind = dyn AllocAnyThread + 'b>,
26+
Self: ClassType<ThreadKind = dyn AnyThread + 'a>,
27+
Self::Super: ClassType<ThreadKind = dyn AnyThread + 'b>,
2828
{
2929
}
3030

@@ -75,14 +75,14 @@ mod tests {
7575

7676
extern_class!(
7777
#[unsafe(super(NSObject))]
78-
#[thread_kind = AllocAnyThread]
78+
#[thread_kind = AnyThread]
7979
#[name = "NSObject"]
8080
struct SetAnyThread;
8181
);
8282

8383
extern_class!(
8484
#[unsafe(super(NSObject))]
85-
#[thread_kind = AllocAnyThread]
85+
#[thread_kind = AnyThread]
8686
#[name = "NSObject"]
8787
struct SendSync;
8888
);

crates/objc2/src/__macro_helpers/define_class.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ use crate::runtime::{
1313
};
1414
#[cfg(debug_assertions)]
1515
use crate::runtime::{AnyProtocol, MethodDescription};
16-
use crate::{AllocAnyThread, ClassType, DefinedClass, Message, ProtocolType};
16+
use crate::{AnyThread, ClassType, DefinedClass, Message, ProtocolType};
1717

1818
use super::defined_ivars::{register_with_ivars, setup_dealloc};
1919
use super::{CopyFamily, InitFamily, MutableCopyFamily, NewFamily, NoneFamily};
2020

2121
/// Helper for determining auto traits of defined classes.
2222
///
23-
/// This will contain either `dyn AllocAnyThread` or `dyn MainThreadOnly`, so
24-
/// it will have no auto traits by default.
23+
/// This will contain either `dyn AnyThread` or `dyn MainThreadOnly`, so it
24+
/// will have no auto traits by default.
2525
#[derive(Debug)]
2626
pub struct ThreadKindAutoTraits<T: ?Sized>(T);
2727

28-
// SAFETY: `AllocAnyThread` does not place restrictions on thread safety.
29-
unsafe impl Send for ThreadKindAutoTraits<dyn AllocAnyThread> {}
28+
// SAFETY: `AnyThread` does not place restrictions on thread safety.
29+
unsafe impl Send for ThreadKindAutoTraits<dyn AnyThread> {}
3030
// SAFETY: Same as above.
31-
unsafe impl Sync for ThreadKindAutoTraits<dyn AllocAnyThread> {}
31+
unsafe impl Sync for ThreadKindAutoTraits<dyn AnyThread> {}
3232

3333
// NOTE: A similar implementation for `dyn MainThreadOnly` is explicitly not
3434
// allowed, as that would enable users to pass something that is tied to the

crates/objc2/src/__macro_helpers/defined_ivars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ mod tests {
435435
use super::*;
436436
use crate::rc::{Allocated, PartialInit, RcTestObject, Retained, ThreadTestData};
437437
use crate::runtime::NSObject;
438-
use crate::{define_class, msg_send, AllocAnyThread, Message};
438+
use crate::{define_class, msg_send, AnyThread, Message};
439439

440440
/// Initialize superclasses, but not own class.
441441
unsafe fn init_only_superclasses<T: DefinedClass>(obj: Allocated<T>) -> Retained<T>

crates/objc2/src/__macro_helpers/msg_send_retained.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ mod tests {
320320

321321
use crate::rc::{autoreleasepool, Allocated, PartialInit, RcTestObject, ThreadTestData};
322322
use crate::runtime::{AnyObject, NSObject, NSObjectProtocol, NSZone};
323-
use crate::{class, define_class, extern_methods, msg_send, test_utils, AllocAnyThread};
323+
use crate::{class, define_class, extern_methods, msg_send, test_utils, AnyThread};
324324

325325
#[test]
326326
fn test_send_message_manuallydrop() {

crates/objc2/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub use self::downcast::DowncastTarget;
133133
pub use self::encode::{Encode, Encoding, RefEncode};
134134
pub use self::main_thread_marker::MainThreadMarker;
135135
pub use self::top_level_traits::{
136-
AllocAnyThread, ClassType, DefinedClass, MainThreadOnly, Message, ProtocolType, ThreadKind,
136+
AnyThread, ClassType, DefinedClass, MainThreadOnly, Message, ProtocolType, ThreadKind,
137137
};
138138

139139
#[cfg(any(feature = "unstable-static-sel", feature = "unstable-static-class"))]
@@ -191,6 +191,10 @@ pub mod declare {
191191
#[deprecated = "renamed to DefinedClass"]
192192
pub use DefinedClass as DeclaredClass;
193193

194+
/// Deprecated alias of [`AnyThread`].
195+
#[deprecated = "renamed to AnyThread"]
196+
pub use AnyThread as AllocAnyThread;
197+
194198
#[cfg(not(feature = "std"))]
195199
compile_error!("The `std` feature currently must be enabled.");
196200

crates/objc2/src/macros/define_class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
/// use objc2_foundation::{CopyingHelper, NSCopying, NSObject, NSObjectProtocol, NSZone};
276276
/// use objc2::rc::{Allocated, Retained};
277277
/// use objc2::{
278-
/// define_class, extern_methods, extern_protocol, msg_send, AllocAnyThread,
278+
/// define_class, extern_methods, extern_protocol, msg_send, AnyThread,
279279
/// ClassType, DefinedClass, ProtocolType,
280280
/// };
281281
///

crates/objc2/src/macros/extern_protocol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ macro_rules! __extern_protocol_check_no_thread_kind {
247247
() => {};
248248
($($ivars:tt)*) => {
249249
$crate::__macro_helpers::compile_error!(
250-
"#[thread_kind = ...] is not supported in extern_protocol!. Add MainThreadOnly or AllocAnyThread bound instead"
250+
"#[thread_kind = ...] is not supported in extern_protocol!. Add MainThreadOnly or AnyThread bound instead"
251251
);
252252
};
253253
}

crates/objc2/src/rc/allocated_partial_init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ mod tests {
399399
#[cfg(feature = "unstable-arbitrary-self-types")]
400400
fn arbitrary_self_types() {
401401
use crate::rc::Retained;
402-
use crate::{extern_methods, AllocAnyThread};
402+
use crate::{extern_methods, AnyThread};
403403

404404
impl RcTestObject {
405405
extern_methods!(

crates/objc2/src/rc/retained.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<T: ?Sized + Message> Retained<T> {
194194
/// ```
195195
/// use objc2::rc::Retained;
196196
/// use objc2::runtime::NSObject;
197-
/// use objc2::{msg_send, AllocAnyThread, ClassType};
197+
/// use objc2::{msg_send, AnyThread, ClassType};
198198
///
199199
/// // Manually using `msg_send!`, pointers and `Retained::from_raw`
200200
/// let obj: *mut NSObject = unsafe { msg_send![NSObject::class(), alloc] };

crates/objc2/src/runtime/nsobject.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ffi::NSUInteger;
77
use crate::rc::{Allocated, DefaultRetained, Retained};
88
use crate::runtime::{AnyClass, AnyObject, AnyProtocol, ImplementedBy, ProtocolObject, Sel};
99
use crate::DowncastTarget;
10-
use crate::{extern_methods, msg_send, AllocAnyThread, ClassType, Message, ProtocolType};
10+
use crate::{extern_methods, msg_send, AnyThread, ClassType, Message, ProtocolType};
1111

1212
/// The root class of most Objective-C class hierarchies.
1313
///
@@ -78,7 +78,7 @@ impl RefUnwindSafe for private::ForDefinedSubclasses {}
7878

7979
unsafe impl ClassType for NSObject {
8080
type Super = AnyObject;
81-
type ThreadKind = dyn AllocAnyThread;
81+
type ThreadKind = dyn AnyThread;
8282
const NAME: &'static str = "NSObject";
8383

8484
#[inline]
@@ -391,10 +391,8 @@ impl NSObject {
391391
extern_methods!(
392392
/// Create a new empty `NSObject`.
393393
///
394-
/// This method is a shorthand for calling [`alloc`] and then
395-
/// [`init`][Self::init].
396-
///
397-
/// [`alloc`]: AllocAnyThread::alloc
394+
/// This method is a shorthand for calling [`alloc`][AnyThread::alloc]
395+
/// and then [`init`][Self::init].
398396
#[unsafe(method(new))]
399397
#[unsafe(method_family = new)]
400398
pub fn new() -> Retained<Self>;
@@ -410,7 +408,7 @@ impl NSObject {
410408
///
411409
/// ```
412410
/// use objc2::runtime::NSObject;
413-
/// use objc2::AllocAnyThread;
411+
/// use objc2::AnyThread;
414412
///
415413
/// let obj = NSObject::init(NSObject::alloc());
416414
/// ```

crates/objc2/src/runtime/nsproxy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::hash;
55

66
use crate::runtime::{AnyClass, AnyObject, NSObjectProtocol, ProtocolObject};
77
use crate::DowncastTarget;
8-
use crate::{AllocAnyThread, ClassType};
8+
use crate::{AnyThread, ClassType};
99

1010
/// An abstract superclass defining an API for objects that act as
1111
/// stand-ins for other objects or for objects that don’t exist yet.
@@ -27,7 +27,7 @@ crate::__extern_class_impl_traits! {
2727

2828
unsafe impl ClassType for NSProxy {
2929
type Super = AnyObject;
30-
type ThreadKind = dyn AllocAnyThread;
30+
type ThreadKind = dyn AnyThread;
3131
const NAME: &'static str = "NSProxy";
3232

3333
#[inline]

crates/objc2/src/top_level_traits.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub unsafe trait Message: RefEncode {
166166
/// Use the trait to allocate a new instance of an object.
167167
///
168168
/// ```
169-
/// use objc2::{msg_send, AllocAnyThread};
169+
/// use objc2::{msg_send, AnyThread};
170170
/// use objc2::rc::Retained;
171171
/// # use objc2::runtime::{NSObject as MyObject};
172172
///
@@ -183,7 +183,7 @@ pub unsafe trait Message: RefEncode {
183183
///
184184
/// ```
185185
/// use objc2::runtime::NSObject;
186-
/// use objc2::{extern_class, ClassType, AllocAnyThread};
186+
/// use objc2::{extern_class, ClassType, AnyThread};
187187
///
188188
/// extern_class!(
189189
/// // SAFETY: The superclass is correctly specified, and the class can be
@@ -224,12 +224,12 @@ pub unsafe trait ClassType: Message {
224224
/// Whether the type can be used from any thread, or from only the main
225225
/// thread.
226226
///
227-
/// One of [`dyn AllocAnyThread`] or [`dyn MainThreadOnly`].
227+
/// One of [`dyn AnyThread`] or [`dyn MainThreadOnly`].
228228
///
229229
/// Setting this makes `ClassType` provide an implementation of either
230-
/// [`AllocAnyThread`] or [`MainThreadOnly`].
230+
/// [`AnyThread`] or [`MainThreadOnly`].
231231
///
232-
/// [`dyn AllocAnyThread`]: AllocAnyThread
232+
/// [`dyn AnyThread`]: AnyThread
233233
/// [`dyn MainThreadOnly`]: MainThreadOnly
234234
type ThreadKind: ?Sized + ThreadKind;
235235

@@ -398,7 +398,7 @@ fn get_protocol(name: &str) -> Option<&'static AnyProtocol> {
398398

399399
// Split into separate traits for better diagnostics
400400
mod private {
401-
pub trait SealedAllocAnyThread {}
401+
pub trait SealedAnyThread {}
402402
pub trait SealedMainThreadOnly {}
403403
pub trait SealedThreadKind {}
404404
}
@@ -426,7 +426,7 @@ mod private {
426426
// impl<T: ?Sized + MainThreadOnly> !AnyThread for T {}
427427
//
428428
// This isn't possible in current Rust though, so we'll have to hack it.
429-
pub unsafe trait AllocAnyThread: private::SealedAllocAnyThread {
429+
pub unsafe trait AnyThread: private::SealedAnyThread {
430430
/// Allocate a new instance of the class.
431431
///
432432
/// The return value can be used directly inside [`msg_send!`] to
@@ -461,14 +461,11 @@ pub unsafe trait AllocAnyThread: private::SealedAllocAnyThread {
461461

462462
// The impl here is a bit bad for diagnostics, but required to prevent users
463463
// implementing the trait themselves.
464-
impl<'a, T: ?Sized + ClassType<ThreadKind = dyn AllocAnyThread + 'a>> private::SealedAllocAnyThread
465-
for T
466-
{
467-
}
468-
unsafe impl<'a, T: ?Sized + ClassType<ThreadKind = dyn AllocAnyThread + 'a>> AllocAnyThread for T {}
464+
impl<'a, T: ?Sized + ClassType<ThreadKind = dyn AnyThread + 'a>> private::SealedAnyThread for T {}
465+
unsafe impl<'a, T: ?Sized + ClassType<ThreadKind = dyn AnyThread + 'a>> AnyThread for T {}
469466

470-
impl<P: ?Sized> private::SealedAllocAnyThread for ProtocolObject<P> {}
471-
unsafe impl<P: ?Sized + AllocAnyThread> AllocAnyThread for ProtocolObject<P> {}
467+
impl<P: ?Sized> private::SealedAnyThread for ProtocolObject<P> {}
468+
unsafe impl<P: ?Sized + AnyThread> AnyThread for ProtocolObject<P> {}
472469

473470
/// Marker trait for classes and protocols that are only safe to use on the
474471
/// main thread.
@@ -569,18 +566,18 @@ unsafe impl<P: ?Sized + MainThreadOnly> MainThreadOnly for ProtocolObject<P> {}
569566

570567
/// The allowed values in [`ClassType::ThreadKind`].
571568
///
572-
/// One of [`dyn AllocAnyThread`] or [`dyn MainThreadOnly`].
569+
/// One of [`dyn AnyThread`] or [`dyn MainThreadOnly`].
573570
///
574-
/// [`dyn AllocAnyThread`]: AllocAnyThread
571+
/// [`dyn AnyThread`]: AnyThread
575572
/// [`dyn MainThreadOnly`]: MainThreadOnly
576573
pub trait ThreadKind: private::SealedThreadKind {
577574
// To mark `ThreadKind` as dyn-incompatible for now.
578575
#[doc(hidden)]
579576
const __DYN_INCOMPATIBLE: ();
580577
}
581578

582-
impl private::SealedThreadKind for dyn AllocAnyThread + '_ {}
583-
impl ThreadKind for dyn AllocAnyThread + '_ {
579+
impl private::SealedThreadKind for dyn AnyThread + '_ {}
580+
impl ThreadKind for dyn AnyThread + '_ {
584581
const __DYN_INCOMPATIBLE: () = ();
585582
}
586583

@@ -594,5 +591,5 @@ mod tests {
594591
use super::*;
595592

596593
#[allow(unused)]
597-
fn dyn_compatible(_: &dyn AllocAnyThread, _: &dyn MainThreadOnly) {}
594+
fn dyn_compatible(_: &dyn AnyThread, _: &dyn MainThreadOnly) {}
598595
}

crates/objc2/src/topics/kvo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::ptr;
2121

2222
use objc2::rc::Retained;
2323
use objc2::runtime::AnyObject;
24-
use objc2::{define_class, msg_send, AllocAnyThread, ClassType, DefinedClass};
24+
use objc2::{define_class, msg_send, AnyThread, ClassType, DefinedClass};
2525
use objc2_foundation::{
2626
ns_string, NSCopying, NSDictionary, NSKeyValueChangeKey, NSKeyValueObservingOptions, NSObject,
2727
NSObjectNSKeyValueObserverRegistration, NSObjectProtocol, NSString,

crates/objc2/src/topics/swift.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Mapping this to Rust would then look something like:
7878
7979
use objc2::rc::{Allocated, Retained};
8080
use objc2::runtime::NSObject;
81-
use objc2::{extern_class, extern_methods, AllocAnyThread};
81+
use objc2::{extern_class, extern_methods, AnyThread};
8282
8383
extern_class!(
8484
#[unsafe(super(NSObject))]

crates/objc2/tests/track_caller.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::Mutex;
1010
use objc2::encode::Encode;
1111
use objc2::rc::{self, Allocated, Retained};
1212
use objc2::runtime::{self, NSObject};
13-
use objc2::{class, define_class, msg_send, AllocAnyThread, ClassType};
13+
use objc2::{class, define_class, msg_send, AnyThread, ClassType};
1414

1515
#[path = "../src/rc/test_object.rs"]
1616
#[allow(dead_code)]

crates/test-fuzz/fuzz_targets/collection_interior_mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::hint::black_box;
1212
use arbitrary::Arbitrary;
1313
use objc2::rc::{autoreleasepool, Retained};
1414
use objc2::runtime::AnyObject;
15-
use objc2::{define_class, msg_send, AllocAnyThread, ClassType, DefinedClass, Message};
15+
use objc2::{define_class, msg_send, AnyThread, ClassType, DefinedClass, Message};
1616
use objc2_foundation::{
1717
CopyingHelper, NSCopying, NSMutableDictionary, NSMutableSet, NSObject, NSObjectProtocol,
1818
NSUInteger, NSZone,

crates/test-ui/ui/define_class_delegate_not_mainthreadonly.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Test that implementing `NSApplicationDelegate` and similar requires
22
//! a `MainThreadOnly` class.
33
use objc2::rc::Retained;
4-
use objc2::{define_class, extern_methods, extern_protocol, AllocAnyThread, MainThreadOnly};
4+
use objc2::{define_class, extern_methods, extern_protocol, AnyThread, MainThreadOnly};
55
use objc2_foundation::{MainThreadMarker, NSNotification, NSObject, NSObjectProtocol};
66

77
// Use fake `NSApplicationDelegate` so that this works on iOS too.
@@ -17,7 +17,7 @@ extern_protocol!(
1717

1818
define_class!(
1919
#[unsafe(super(NSObject))]
20-
#[thread_kind = AllocAnyThread] // Not `MainThreadOnly`
20+
#[thread_kind = AnyThread] // Not `MainThreadOnly`
2121
struct CustomObject;
2222

2323
unsafe impl NSObjectProtocol for CustomObject {}

crates/test-ui/ui/define_class_delegate_not_mainthreadonly.stderr

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/test-ui/ui/extern_class_root.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::ops::Deref;
22

33
use objc2::encode::{Encoding, RefEncode};
44
use objc2::runtime::AnyObject;
5-
use objc2::{extern_class, AllocAnyThread, Message};
5+
use objc2::{extern_class, AnyThread, Message};
66

77
#[repr(transparent)]
88
struct MyObject(AnyObject);
@@ -23,7 +23,7 @@ impl Deref for MyObject {
2323

2424
extern_class!(
2525
#[unsafe(super(MyObject))]
26-
#[thread_kind = AllocAnyThread]
26+
#[thread_kind = AnyThread]
2727
pub struct MyRootClass;
2828
);
2929

0 commit comments

Comments
 (0)