From aefc96b0d0e01c87718438498ecc79b4a0dcf662 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 22 Jan 2025 02:03:27 +0100 Subject: [PATCH] Remove more internal mentions of `id`/`Id` Part of https://github.com/madsmtm/objc2/issues/617. --- .../objc2/src/__macro_helpers/method_family.rs | 2 +- .../src/__macro_helpers/msg_send_retained.rs | 12 ++++++------ .../src/__macro_helpers/retain_semantics.rs | 4 ++-- crates/objc2/src/__macro_helpers/writeback.rs | 2 +- crates/objc2/src/macros/__attribute_helpers.rs | 2 +- crates/objc2/src/macros/extern_protocol.rs | 13 ++++++------- crates/objc2/src/rc/retained.rs | 4 ++-- crates/objc2/src/rc/retained_traits.rs | 6 +++--- crates/objc2/src/rc/test_object.rs | 4 ++-- crates/objc2/src/rc/weak.rs | 4 ++-- crates/objc2/tests/define_class.rs | 8 ++++---- crates/objc2/tests/define_class_self.rs | 10 +++++----- crates/objc2/tests/macros_mainthreadmarker.rs | 6 +++--- crates/objc2/tests/track_caller.rs | 4 ++-- .../test-ui/ui/define_class_invalid_receiver.rs | 16 ++++++++-------- crates/test-ui/ui/define_class_invalid_syntax.rs | 14 +++++++------- .../ui/define_class_invalid_syntax.stderr | 8 ++++---- crates/test-ui/ui/define_class_invalid_type2.rs | 4 ++-- .../ui/define_class_mut_self_not_mutable.rs | 4 ++-- .../ui/extern_methods_selector_twice.stderr | 2 +- crates/tests/src/block.rs | 2 +- crates/tests/src/test_object.rs | 2 +- .../objc2-app-kit/examples/delegate.rs | 4 ++-- 23 files changed, 68 insertions(+), 69 deletions(-) diff --git a/crates/objc2/src/__macro_helpers/method_family.rs b/crates/objc2/src/__macro_helpers/method_family.rs index 4e924ad0f..ec27bb796 100644 --- a/crates/objc2/src/__macro_helpers/method_family.rs +++ b/crates/objc2/src/__macro_helpers/method_family.rs @@ -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`, /// which means it can't be a class method! diff --git a/crates/objc2/src/__macro_helpers/msg_send_retained.rs b/crates/objc2/src/__macro_helpers/msg_send_retained.rs index 849e08165..cc041f46f 100644 --- a/crates/objc2/src/__macro_helpers/msg_send_retained.rs +++ b/crates/objc2/src/__macro_helpers/msg_send_retained.rs @@ -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| { @@ -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, @@ -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 diff --git a/crates/objc2/src/__macro_helpers/retain_semantics.rs b/crates/objc2/src/__macro_helpers/retain_semantics.rs index 7dae478ba..be3d3eae2 100644 --- a/crates/objc2/src/__macro_helpers/retain_semantics.rs +++ b/crates/objc2/src/__macro_helpers/retain_semantics.rs @@ -364,8 +364,8 @@ where // // InitFamily // -// We restrict `init` methods such that, if they return `Id`, the receiver -// must be `Allocated` with the same generic parameter. +// We restrict `init` methods such that, if they return `Retained`, the +// receiver must be `Allocated` with the same generic parameter. // // Simple return types have no restriction. // diff --git a/crates/objc2/src/__macro_helpers/writeback.rs b/crates/objc2/src/__macro_helpers/writeback.rs index d1837ef7c..9e1d09ffa 100644 --- a/crates/objc2/src/__macro_helpers/writeback.rs +++ b/crates/objc2/src/__macro_helpers/writeback.rs @@ -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(); diff --git a/crates/objc2/src/macros/__attribute_helpers.rs b/crates/objc2/src/macros/__attribute_helpers.rs index d54d31ef3..f54e6289a 100644 --- a/crates/objc2/src/macros/__attribute_helpers.rs +++ b/crates/objc2/src/macros/__attribute_helpers.rs @@ -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)*) diff --git a/crates/objc2/src/macros/extern_protocol.rs b/crates/objc2/src/macros/extern_protocol.rs index 17bbee48d..1de2537ab 100644 --- a/crates/objc2/src/macros/extern_protocol.rs +++ b/crates/objc2/src/macros/extern_protocol.rs @@ -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. @@ -107,14 +106,14 @@ /// /// // 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>; /// -/// #[method_id(writableTypeIdentifiersForItemProvider)] +/// #[method(writableTypeIdentifiersForItemProvider)] /// fn writableTypeIdentifiersForItemProvider_class() /// -> Retained>; /// @@ -122,7 +121,7 @@ /// // `define_class!` would not need to implement them. /// /// #[optional] -/// #[method_id(writableTypeIdentifiersForItemProvider)] +/// #[method(writableTypeIdentifiersForItemProvider)] /// fn writableTypeIdentifiersForItemProvider(&self) /// -> Retained>; /// diff --git a/crates/objc2/src/rc/retained.rs b/crates/objc2/src/rc/retained.rs index b22415faf..29a2cd1b2 100644 --- a/crates/objc2/src/rc/retained.rs +++ b/crates/objc2/src/rc/retained.rs @@ -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", @@ -998,7 +998,7 @@ mod tests { /// Test that `Retained` is covariant over `T`. #[allow(unused)] - fn assert_id_variance<'b>(obj: Retained>) -> Retained> { + fn assert_retained_variance<'b>(obj: Retained>) -> Retained> { obj } diff --git a/crates/objc2/src/rc/retained_traits.rs b/crates/objc2/src/rc/retained_traits.rs index 4d22385da..5f43b9a1c 100644 --- a/crates/objc2/src/rc/retained_traits.rs +++ b/crates/objc2/src/rc/retained_traits.rs @@ -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. /// @@ -29,7 +29,7 @@ impl Default for Retained { // 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; @@ -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: Sized { /// Creates an `Retained` from an iterator. fn retained_from_iter(iter: I) -> Retained diff --git a/crates/objc2/src/rc/test_object.rs b/crates/objc2/src/rc/test_object.rs index 1c23b886c..46bbd9a54 100644 --- a/crates/objc2/src/rc/test_object.rs +++ b/crates/objc2/src/rc/test_object.rs @@ -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> { @@ -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>, diff --git a/crates/objc2/src/rc/weak.rs b/crates/objc2/src/rc/weak.rs index 8445666d6..5375fc6ef 100644 --- a/crates/objc2/src/rc/weak.rs +++ b/crates/objc2/src/rc/weak.rs @@ -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 { /// We give the runtime the address to this box, so that it can modify it /// even if the `Weak` is moved. @@ -43,6 +42,7 @@ pub struct Weak { /// /// 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>, /// Weak inherits variance, dropck and various marker traits from /// `Retained`. diff --git a/crates/objc2/tests/define_class.rs b/crates/objc2/tests/define_class.rs index 0d3c4745c..8d8ac87e8 100644 --- a/crates/objc2/tests/define_class.rs +++ b/crates/objc2/tests/define_class.rs @@ -377,13 +377,13 @@ define_class!( unreachable!() } - #[method_id(unreachableId)] - fn unreachable_id(&self) -> Retained { + #[method_id(unreachableRetained)] + fn unreachable_retained(&self) -> Retained { unreachable!() } - #[method_id(unreachableClassId)] - fn unreachable_class_id() -> Retained { + #[method_id(unreachableClassRetained)] + fn unreachable_class_retained() -> Retained { unreachable!() } } diff --git a/crates/objc2/tests/define_class_self.rs b/crates/objc2/tests/define_class_self.rs index 5916f1e50..fa88a2283 100644 --- a/crates/objc2/tests/define_class_self.rs +++ b/crates/objc2/tests/define_class_self.rs @@ -13,12 +13,12 @@ impl GetSameType for T { type SameType = T; } -trait GetId { - type IdType; +trait GetRetained { + type RetainedType; } -impl GetId for T { - type IdType = Retained; +impl GetRetained for T { + type RetainedType = Retained; } macro_rules! get_self { @@ -53,7 +53,7 @@ define_class!( } #[method_id(test5)] - fn test5(&self) -> ::IdType { + fn test5(&self) -> ::RetainedType { unimplemented!() } } diff --git a/crates/objc2/tests/macros_mainthreadmarker.rs b/crates/objc2/tests/macros_mainthreadmarker.rs index 35a3d4eaf..16c0e15e7 100644 --- a/crates/objc2/tests/macros_mainthreadmarker.rs +++ b/crates/objc2/tests/macros_mainthreadmarker.rs @@ -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; } ); @@ -28,7 +28,7 @@ define_class!( arg + 1 } - #[method_id(myMethodId:)] + #[method_id(myMethodRetained:)] fn _my_mainthreadonly_method_retained(arg: &Self) -> Retained { unsafe { Retained::retain(arg as *const Self as *mut Self).unwrap() } } @@ -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, diff --git a/crates/objc2/tests/track_caller.rs b/crates/objc2/tests/track_caller.rs index 253f5f7a8..e2aa5335f 100644 --- a/crates/objc2/tests/track_caller.rs +++ b/crates/objc2/tests/track_caller.rs @@ -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); @@ -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(); diff --git a/crates/test-ui/ui/define_class_invalid_receiver.rs b/crates/test-ui/ui/define_class_invalid_receiver.rs index 06c95a6af..3eb17ba47 100644 --- a/crates/test-ui/ui/define_class_invalid_receiver.rs +++ b/crates/test-ui/ui/define_class_invalid_receiver.rs @@ -14,8 +14,8 @@ define_class!( unimplemented!() } - #[method(testIdSelf)] - fn test_id_self(this: Retained) { + #[method(testRetainedSelf)] + fn test_retained_self(this: Retained) { unimplemented!() } @@ -36,18 +36,18 @@ define_class!( } unsafe impl CustomObject { - #[method_id(testBoxId)] - fn test_box_id(self: Box) -> Retained { + #[method_id(testBoxRetained)] + fn test_box_retained(self: Box) -> Retained { unimplemented!() } - #[method_id(testIdSelfId)] - fn test_id_self_id(this: Retained) -> Retained { + #[method_id(testRetainedSelfRetained)] + fn test_retained_self_retained(this: Retained) -> Retained { unimplemented!() } - #[method_id(testSelfId)] - fn test_self_id(this: Self) -> Retained { + #[method_id(testSelfRetained)] + fn test_self_retained(this: Self) -> Retained { unimplemented!() } } diff --git a/crates/test-ui/ui/define_class_invalid_syntax.rs b/crates/test-ui/ui/define_class_invalid_syntax.rs index 7423546a1..ad7aa0005 100644 --- a/crates/test-ui/ui/define_class_invalid_syntax.rs +++ b/crates/test-ui/ui/define_class_invalid_syntax.rs @@ -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!() } @@ -83,27 +83,27 @@ define_class!( unsafe impl InvalidMethodDeclarations { #[method_id(alloc)] - fn test_method_id_bad_selector1() -> Retained { + fn test_retained_bad_selector1() -> Retained { unimplemented!() } #[method_id(retain)] - fn test_method_id_bad_selector2() -> Retained { + fn test_retained_bad_selector2() -> Retained { unimplemented!() } #[method_id(release)] - fn test_method_id_bad_selector3() -> Retained { + fn test_retained_bad_selector3() -> Retained { unimplemented!() } #[method_id(autorelease)] - fn test_method_id_bad_selector4() -> Retained { + fn test_retained_bad_selector4() -> Retained { unimplemented!() } #[method_id(dealloc)] - fn test_method_id_bad_selector5() -> Retained { + fn test_retained_bad_selector5() -> Retained { unimplemented!() } } diff --git a/crates/test-ui/ui/define_class_invalid_syntax.stderr b/crates/test-ui/ui/define_class_invalid_syntax.stderr index 72b5e931d..b9cbdf8dc 100644 --- a/crates/test-ui/ui/define_class_invalid_syntax.stderr +++ b/crates/test-ui/ui/define_class_invalid_syntax.stderr @@ -11,7 +11,7 @@ error: must specify the desired selector using `#[method(...)]` or `#[method_id( | = note: this error originates in the macro `$crate::__extract_method_attributes_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method` attribute twice +error: cannot specify the `method`/`method_id` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( @@ -24,7 +24,7 @@ error: cannot specify the `method` attribute twice | = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method` attribute twice +error: cannot specify the `method`/`method_id` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( @@ -241,7 +241,7 @@ error: must specify the desired selector using `#[method(...)]` or `#[method_id( | = note: this error originates in the macro `$crate::__extract_method_attributes_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method` attribute twice +error: cannot specify the `method`/`method_id` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( @@ -254,7 +254,7 @@ error: cannot specify the `method` attribute twice | = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method` attribute twice +error: cannot specify the `method`/`method_id` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( diff --git a/crates/test-ui/ui/define_class_invalid_type2.rs b/crates/test-ui/ui/define_class_invalid_type2.rs index 771a379f5..1d9268135 100644 --- a/crates/test-ui/ui/define_class_invalid_type2.rs +++ b/crates/test-ui/ui/define_class_invalid_type2.rs @@ -13,8 +13,8 @@ define_class!( unimplemented!() } - #[method_id(methodIdNotId)] - fn test_method_id_not_id(&self) -> i32 { + #[method_id(notRetained)] + fn test_not_retained(&self) -> i32 { unimplemented!() } } diff --git a/crates/test-ui/ui/define_class_mut_self_not_mutable.rs b/crates/test-ui/ui/define_class_mut_self_not_mutable.rs index c1a00c973..9759de503 100644 --- a/crates/test-ui/ui/define_class_mut_self_not_mutable.rs +++ b/crates/test-ui/ui/define_class_mut_self_not_mutable.rs @@ -18,8 +18,8 @@ define_class!( unimplemented!() } - #[method_id(testMethodId)] - fn test_method_id(&mut self) -> Retained { + #[method_id(testRetained)] + fn test_retained(&mut self) -> Retained { unimplemented!() } } diff --git a/crates/test-ui/ui/extern_methods_selector_twice.stderr b/crates/test-ui/ui/extern_methods_selector_twice.stderr index f754c5b62..e67be64ad 100644 --- a/crates/test-ui/ui/extern_methods_selector_twice.stderr +++ b/crates/test-ui/ui/extern_methods_selector_twice.stderr @@ -1,4 +1,4 @@ -error: cannot specify the `method` attribute twice +error: cannot specify the `method`/`method_id` attribute twice --> ui/extern_methods_selector_twice.rs | | / extern_methods!( diff --git a/crates/tests/src/block.rs b/crates/tests/src/block.rs index e1fa31c72..9401e9ec5 100644 --- a/crates/tests/src/block.rs +++ b/crates/tests/src/block.rs @@ -563,7 +563,7 @@ fn retain_release_stack_block() { } #[test] -fn capture_id() { +fn capture_retained() { let obj1 = NSObject::new(); let obj2 = NSObject::new(); let closure = move || Bool::new(obj1 == obj2); diff --git a/crates/tests/src/test_object.rs b/crates/tests/src/test_object.rs index 843bdcdee..4bd9db327 100644 --- a/crates/tests/src/test_object.rs +++ b/crates/tests/src/test_object.rs @@ -296,7 +296,7 @@ fn test_object() { )] fn test_protocol() { let obj = MyTestObject::new(); - let proto: Retained> = ProtocolObject::from_id(obj); + let proto: Retained> = ProtocolObject::from_retained(obj); assert_eq!(proto.a(), 1); assert_eq!(MyTestObject::b(), 2); assert_eq!(proto.c().as_i32(), 3); diff --git a/framework-crates/objc2-app-kit/examples/delegate.rs b/framework-crates/objc2-app-kit/examples/delegate.rs index 53ab8743a..8dfbed92b 100644 --- a/framework-crates/objc2-app-kit/examples/delegate.rs +++ b/framework-crates/objc2-app-kit/examples/delegate.rs @@ -15,7 +15,7 @@ struct Ivars { box_ivar: Box, maybe_box_ivar: Option>, id_ivar: Retained, - maybe_id_ivar: Option>, + maybe_retained_ivar: Option>, } define_class!( @@ -56,7 +56,7 @@ impl AppDelegate { box_ivar: Box::new(2), maybe_box_ivar: None, id_ivar: NSString::from_str("abc"), - maybe_id_ivar: Some(ns_string!("def").copy()), + maybe_retained_ivar: Some(ns_string!("def").copy()), }); unsafe { msg_send![super(this), init] } }