Skip to content

Commit

Permalink
Remove more internal mentions of id/Id
Browse files Browse the repository at this point in the history
Part of #617.
  • Loading branch information
madsmtm committed Jan 22, 2025
1 parent 190e1d6 commit aefc96b
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 69 deletions.
2 changes: 1 addition & 1 deletion crates/objc2/src/__macro_helpers/method_family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// The added restrictions are:
/// - `new`, `alloc`, `copy` and `mutableCopy`: The method must return a
/// retainable object pointer type - we ensure this by making
/// `message_send_id` return `Retained`.
/// `message_send` return `Retained`.
/// - `init`: The method must be an instance method and must return an
/// Objective-C pointer type - We ensure this by taking `Allocated<T>`,
/// which means it can't be a class method!
Expand Down
12 changes: 6 additions & 6 deletions crates/objc2/src/__macro_helpers/msg_send_retained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ mod tests {
}
};

macro_rules! test_error_id {
macro_rules! test_error_retained {
($expected:expr, $if_autorelease_not_skipped:expr, $sel:ident, $($obj:tt)*) => {
// Succeeds
let res = autoreleasepool(|_pool| {
Expand Down Expand Up @@ -862,22 +862,22 @@ mod tests {
}

#[test]
fn test_error_id() {
fn test_error_retained() {
let mut expected = ThreadTestData::current();

let cls = RcTestObject::class();
test_error_id!(
test_error_retained!(
expected,
IF_AUTORELEASE_NOT_SKIPPED_ARM_HACK,
idAndShouldError,
cls
);
test_error_id!(expected, 0, newAndShouldError, cls);
test_error_retained!(expected, 0, newAndShouldError, cls);

let obj = RcTestObject::new();
expected.alloc += 1;
expected.init += 1;
test_error_id!(
test_error_retained!(
expected,
IF_AUTORELEASE_NOT_SKIPPED_ARM_HACK,
idAndShouldError,
Expand All @@ -886,7 +886,7 @@ mod tests {

expected.alloc -= 1;
expected.release -= 1;
test_error_id!(expected, 0, initAndShouldError, {
test_error_retained!(expected, 0, initAndShouldError, {
expected.alloc += 1;
expected.release += 1;
// Drop flag ensures newly allocated objects do not drop
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/__macro_helpers/retain_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ where
//
// InitFamily
//
// We restrict `init` methods such that, if they return `Id<T>`, the receiver
// must be `Allocated<T>` with the same generic parameter.
// We restrict `init` methods such that, if they return `Retained<T>`, the
// receiver must be `Allocated<T>` with the same generic parameter.
//
// Simple return types have no restriction.
//
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/__macro_helpers/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ mod tests {
const AUTORELEASE_SKIPPED: bool = cfg!(feature = "gnustep-1-7");

#[test]
fn test_id_interaction() {
fn test_retained_interaction() {
let mut expected = ThreadTestData::current();
let cls = RcTestObject::class();

Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/macros/__attribute_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ macro_rules! __extract_method_attributes_inner {
($out_macro:path)
$($out_args:tt)*
} => {
$crate::__handle_duplicate!("method"; $($method)*);
$crate::__handle_duplicate!("method`/`method_id"; $($method)*);
$crate::__extract_method_attributes_inner! {
($($rest)*)

Expand Down
13 changes: 6 additions & 7 deletions crates/objc2/src/macros/extern_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
///
/// This macro creates an `unsafe` trait with the specified methods. A default
/// implementation of the method is generated based on the selector specified
/// with `#[method(a:selector:)]` or `#[method_id(a:selector:)]`.
/// Similar to [`extern_methods!`], you can use the
/// `#[unsafe(method_family = ...)]` attribute to override the inferred method
/// family.
/// with `#[method(a:selector:)]`. Similar to [`extern_methods!`], you can use
/// the `#[unsafe(method_family = ...)]` attribute to override the inferred
/// method family.
///
/// Other protocols that this protocol conforms to / inherits can be specified
/// as supertraits.
Expand Down Expand Up @@ -107,22 +106,22 @@
///
/// // This method we mark as `unsafe`, since we aren't using the correct
/// // type for the completion handler
/// #[method_id(loadDataWithTypeIdentifier:forItemProviderCompletionHandler:)]
/// #[method(loadDataWithTypeIdentifier:forItemProviderCompletionHandler:)]
/// unsafe fn loadData(
/// &self,
/// type_identifier: &NSString,
/// completion_handler: *mut c_void,
/// ) -> Option<Retained<NSProgress>>;
///
/// #[method_id(writableTypeIdentifiersForItemProvider)]
/// #[method(writableTypeIdentifiersForItemProvider)]
/// fn writableTypeIdentifiersForItemProvider_class()
/// -> Retained<NSArray<NSString>>;
///
/// // The rest of these are optional, which means that a user of
/// // `define_class!` would not need to implement them.
///
/// #[optional]
/// #[method_id(writableTypeIdentifiersForItemProvider)]
/// #[method(writableTypeIdentifiersForItemProvider)]
/// fn writableTypeIdentifiersForItemProvider(&self)
/// -> Retained<NSArray<NSString>>;
///
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/rc/retained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ use crate::{ffi, ClassType, DowncastTarget, Message};
/// ```
#[repr(transparent)]
#[doc(alias = "id")]
#[doc(alias = "Id")]
#[doc(alias = "Id")] // Previous name
#[doc(alias = "StrongPtr")]
#[cfg_attr(
feature = "unstable-coerce-pointee",
Expand Down Expand Up @@ -998,7 +998,7 @@ mod tests {

/// Test that `Retained<T>` is covariant over `T`.
#[allow(unused)]
fn assert_id_variance<'b>(obj: Retained<MyObject<'static>>) -> Retained<MyObject<'b>> {
fn assert_retained_variance<'b>(obj: Retained<MyObject<'static>>) -> Retained<MyObject<'b>> {
obj
}

Expand Down
6 changes: 3 additions & 3 deletions crates/objc2/src/rc/retained_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::Retained;

/// Helper trait to implement [`Default`] on [`Retained`].
#[doc(alias = "DefaultId")]
#[doc(alias = "DefaultId")] // Previous name
pub trait DefaultRetained {
/// The default [`Retained`] for a type.
///
Expand All @@ -29,7 +29,7 @@ impl<T: ?Sized + DefaultRetained> Default for Retained<T> {
// without this helper trait.
//
// [box-move]: https://doc.rust-lang.org/reference/expressions.html#moved-and-copied-types
#[doc(alias = "IdIntoIterator")]
#[doc(alias = "IdIntoIterator")] // Previous name
pub trait RetainedIntoIterator {
/// The type of the elements being iterated over.
type Item;
Expand Down Expand Up @@ -99,7 +99,7 @@ where
///
/// This should be implemented in exactly the same fashion as if you were
/// implementing `FromIterator` for your type normally.
#[doc(alias = "IdFromIterator")]
#[doc(alias = "IdFromIterator")] // Previous name
pub trait RetainedFromIterator<T>: Sized {
/// Creates an `Retained` from an iterator.
fn retained_from_iter<I>(iter: I) -> Retained<Self>
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/rc/test_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ define_class!(
}

#[method_id(idAndShouldError:error:)]
fn class_error_id(
fn class_error_retained(
should_error: bool,
err: Option<&mut *mut RcTestObject>,
) -> Option<Retained<Self>> {
Expand All @@ -217,7 +217,7 @@ define_class!(
}

#[method_id(idAndShouldError:error:)]
fn instance_error_id(
fn instance_error_retained(
self: &Self,
should_error: bool,
err: Option<&mut *mut RcTestObject>,
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/rc/weak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use crate::{ffi, Message};
/// [`sync::Weak`]: std::sync::Weak
/// [`sync::Arc`]: std::sync::Arc
#[repr(transparent)] // This is not a public guarantee
#[doc(alias = "WeakId")]
// TODO: Add derive(CoercePointee) once this doesn't Box internally.
#[doc(alias = "WeakId")] // Previous name
pub struct Weak<T: ?Sized> {
/// We give the runtime the address to this box, so that it can modify it
/// even if the `Weak` is moved.
Expand All @@ -43,6 +42,7 @@ pub struct Weak<T: ?Sized> {
///
/// TODO: Verify the need for UnsafeCell?
/// TODO: Investigate if we can avoid some allocations using `Pin`.
/// TODO: Add derive(CoercePointee) once this doesn't Box internally.
inner: Box<UnsafeCell<*mut AnyObject>>,
/// Weak inherits variance, dropck and various marker traits from
/// `Retained<T>`.
Expand Down
8 changes: 4 additions & 4 deletions crates/objc2/tests/define_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ define_class!(
unreachable!()
}

#[method_id(unreachableId)]
fn unreachable_id(&self) -> Retained<Self> {
#[method_id(unreachableRetained)]
fn unreachable_retained(&self) -> Retained<Self> {
unreachable!()
}

#[method_id(unreachableClassId)]
fn unreachable_class_id() -> Retained<Self> {
#[method_id(unreachableClassRetained)]
fn unreachable_class_retained() -> Retained<Self> {
unreachable!()
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/objc2/tests/define_class_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ impl<T: ?Sized> GetSameType for T {
type SameType = T;
}

trait GetId {
type IdType;
trait GetRetained {
type RetainedType;
}

impl<T> GetId for T {
type IdType = Retained<T>;
impl<T> GetRetained for T {
type RetainedType = Retained<T>;
}

macro_rules! get_self {
Expand Down Expand Up @@ -53,7 +53,7 @@ define_class!(
}

#[method_id(test5)]
fn test5(&self) -> <Self as GetId>::IdType {
fn test5(&self) -> <Self as GetRetained>::RetainedType {
unimplemented!()
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/objc2/tests/macros_mainthreadmarker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern_protocol!(
#[method(myMethod:)]
fn protocol_method(mtm: MainThreadMarker, arg: i32) -> i32;

#[method(myMethodId:)]
#[method(myMethodRetained:)]
fn protocol_method_retained(mtm: MainThreadMarker, arg: &Self) -> Retained<Self>;
}
);
Expand All @@ -28,7 +28,7 @@ define_class!(
arg + 1
}

#[method_id(myMethodId:)]
#[method_id(myMethodRetained:)]
fn _my_mainthreadonly_method_retained(arg: &Self) -> Retained<Self> {
unsafe { Retained::retain(arg as *const Self as *mut Self).unwrap() }
}
Expand All @@ -51,7 +51,7 @@ extern_methods!(
#[method(myMethod:)]
fn method(mtm: MainThreadMarker, arg: i32, mtm2: MainThreadMarker) -> i32;

#[method(myMethodId:)]
#[method(myMethodRetained:)]
fn method_retained(
mtm: MainThreadMarker,
arg: &Self,
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/tests/track_caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn test_track_caller() {
}
}

test_id_unwrap(&checker);
test_retained_unwrap(&checker);

if cfg!(feature = "catch-all") {
test_catch_all(&checker);
Expand Down Expand Up @@ -151,7 +151,7 @@ fn test_error_methods(checker: &PanicChecker) {
});
}

fn test_id_unwrap(checker: &PanicChecker) {
fn test_retained_unwrap(checker: &PanicChecker) {
let cls = RcTestObject::class();
let obj = RcTestObject::new();

Expand Down
16 changes: 8 additions & 8 deletions crates/test-ui/ui/define_class_invalid_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ define_class!(
unimplemented!()
}

#[method(testIdSelf)]
fn test_id_self(this: Retained<Self>) {
#[method(testRetainedSelf)]
fn test_retained_self(this: Retained<Self>) {
unimplemented!()
}

Expand All @@ -36,18 +36,18 @@ define_class!(
}

unsafe impl CustomObject {
#[method_id(testBoxId)]
fn test_box_id(self: Box<Self>) -> Retained<Self> {
#[method_id(testBoxRetained)]
fn test_box_retained(self: Box<Self>) -> Retained<Self> {
unimplemented!()
}

#[method_id(testIdSelfId)]
fn test_id_self_id(this: Retained<Self>) -> Retained<Self> {
#[method_id(testRetainedSelfRetained)]
fn test_retained_self_retained(this: Retained<Self>) -> Retained<Self> {
unimplemented!()
}

#[method_id(testSelfId)]
fn test_self_id(this: Self) -> Retained<Self> {
#[method_id(testSelfRetained)]
fn test_self_retained(this: Self) -> Retained<Self> {
unimplemented!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/test-ui/ui/define_class_invalid_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ define_class!(
#[method(duplicateAttributeDifferent)]
fn test_duplicate_attribute_different() {}

#[method_id(testMethodId)]
fn test_method_id_no_return() {
#[method_id(testMethodRetained)]
fn test_retained_no_return() {
unimplemented!()
}

Expand Down Expand Up @@ -83,27 +83,27 @@ define_class!(

unsafe impl InvalidMethodDeclarations {
#[method_id(alloc)]
fn test_method_id_bad_selector1() -> Retained<Self> {
fn test_retained_bad_selector1() -> Retained<Self> {
unimplemented!()
}

#[method_id(retain)]
fn test_method_id_bad_selector2() -> Retained<Self> {
fn test_retained_bad_selector2() -> Retained<Self> {
unimplemented!()
}

#[method_id(release)]
fn test_method_id_bad_selector3() -> Retained<Self> {
fn test_retained_bad_selector3() -> Retained<Self> {
unimplemented!()
}

#[method_id(autorelease)]
fn test_method_id_bad_selector4() -> Retained<Self> {
fn test_retained_bad_selector4() -> Retained<Self> {
unimplemented!()
}

#[method_id(dealloc)]
fn test_method_id_bad_selector5() -> Retained<Self> {
fn test_retained_bad_selector5() -> Retained<Self> {
unimplemented!()
}
}
Expand Down
Loading

0 comments on commit aefc96b

Please sign in to comment.