diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index 87b2cdb1d8..e8cd10bf29 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -76,7 +76,7 @@ jobs: matrix: # TODO(#1954): These should be run on mac too, but turns out they're # broken. - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c405c7da..7f206c9cc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,8 +140,13 @@ ## Added + * Objective-C structs now derive `Debug` and `Copy` to support C and Objective-C structs. [(#2176)][] + ## Fixed + * Fixed lifetimes with Objective-C trait templates. [(#2176)][] + * Fixed objc imports for non-`#[macro_use]` use. [(#2176)][] + ## Changed * cexpr and nom have been updated, new msrv is 1.46 (#2107). @@ -154,6 +159,9 @@ ## Security + + [(#2176)]: https://github.com/rust-lang/rust-bindgen/pull/2176 + # 0.59.1 Released 2021/07/26 diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index ffb21d13b3..a0a0670cb2 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -4129,7 +4129,7 @@ impl CodeGenerator for ObjCInterface { .collect(); quote! { - pub trait #trait_name <#(#template_names),*> : #trait_constraints { + pub trait #trait_name <#(#template_names:'static),*> : #trait_constraints { #( #impl_items )* } } @@ -4145,7 +4145,7 @@ impl CodeGenerator for ObjCInterface { if !self.is_category() && !self.is_protocol() { let struct_block = quote! { #[repr(transparent)] - #[derive(Clone)] + #[derive(Debug, Copy, Clone)] pub struct #class_name(pub id); impl std::ops::Deref for #class_name { type Target = objc::runtime::Object; @@ -4159,7 +4159,7 @@ impl CodeGenerator for ObjCInterface { impl #class_name { pub fn alloc() -> Self { Self(unsafe { - msg_send!(objc::class!(#class_name), alloc) + msg_send!(class!(#class_name), alloc) }) } } @@ -4381,7 +4381,7 @@ pub mod utils { } } else { quote! { - use objc; + use objc::{self, msg_send, sel, sel_impl, class}; } }; diff --git a/tests/expectations/Cargo.toml b/tests/expectations/Cargo.toml index c78cc09a0b..f8006afeab 100644 --- a/tests/expectations/Cargo.toml +++ b/tests/expectations/Cargo.toml @@ -7,6 +7,7 @@ authors = [ "Emilio Cobos Álvarez ", "The Servo project developers", ] +edition = "2018" [dependencies] objc = "0.2" diff --git a/tests/expectations/tests/libclang-4/objc_inheritance.rs b/tests/expectations/tests/libclang-4/objc_inheritance.rs index 5f07dbaab1..f1c2a88cb0 100644 --- a/tests/expectations/tests/libclang-4/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-4/objc_inheritance.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} @@ -63,7 +62,7 @@ impl std::convert::TryFrom for Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz { unsafe impl objc::Message for Baz {} impl Baz { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + Self(unsafe { msg_send!(class!(Baz), alloc) }) } } impl IBar for Baz {} diff --git a/tests/expectations/tests/libclang-4/objc_template.rs b/tests/expectations/tests/libclang-4/objc_template.rs index 36b7d22baa..53caa661c6 100644 --- a/tests/expectations/tests/libclang-4/objc_template.rs +++ b/tests/expectations/tests/libclang-4/objc_template.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { +pub trait IFoo: Sized + std::ops::Deref { unsafe fn get(&self) -> *mut ObjectType where ::Target: objc::Message + Sized, @@ -35,7 +34,7 @@ pub trait IFoo: Sized + std::ops::Deref { } } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric { unsafe impl objc::Message for FooMultiGeneric {} impl FooMultiGeneric { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } impl IFooMultiGeneric for FooMultiGeneric { } -pub trait IFooMultiGeneric: +pub trait IFooMultiGeneric: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType diff --git a/tests/expectations/tests/libclang-5/objc_inheritance.rs b/tests/expectations/tests/libclang-5/objc_inheritance.rs index 5f07dbaab1..f1c2a88cb0 100644 --- a/tests/expectations/tests/libclang-5/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-5/objc_inheritance.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} @@ -63,7 +62,7 @@ impl std::convert::TryFrom for Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz { unsafe impl objc::Message for Baz {} impl Baz { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + Self(unsafe { msg_send!(class!(Baz), alloc) }) } } impl IBar for Baz {} diff --git a/tests/expectations/tests/libclang-5/objc_template.rs b/tests/expectations/tests/libclang-5/objc_template.rs index 36b7d22baa..53caa661c6 100644 --- a/tests/expectations/tests/libclang-5/objc_template.rs +++ b/tests/expectations/tests/libclang-5/objc_template.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { +pub trait IFoo: Sized + std::ops::Deref { unsafe fn get(&self) -> *mut ObjectType where ::Target: objc::Message + Sized, @@ -35,7 +34,7 @@ pub trait IFoo: Sized + std::ops::Deref { } } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric { unsafe impl objc::Message for FooMultiGeneric {} impl FooMultiGeneric { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } impl IFooMultiGeneric for FooMultiGeneric { } -pub trait IFooMultiGeneric: +pub trait IFooMultiGeneric: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType diff --git a/tests/expectations/tests/libclang-9/objc_inheritance.rs b/tests/expectations/tests/libclang-9/objc_inheritance.rs index 5f07dbaab1..f1c2a88cb0 100644 --- a/tests/expectations/tests/libclang-9/objc_inheritance.rs +++ b/tests/expectations/tests/libclang-9/objc_inheritance.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} @@ -63,7 +62,7 @@ impl std::convert::TryFrom for Bar { impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Baz(pub id); impl std::ops::Deref for Baz { type Target = objc::runtime::Object; @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz { unsafe impl objc::Message for Baz {} impl Baz { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Baz), alloc) }) + Self(unsafe { msg_send!(class!(Baz), alloc) }) } } impl IBar for Baz {} diff --git a/tests/expectations/tests/libclang-9/objc_template.rs b/tests/expectations/tests/libclang-9/objc_template.rs index 88cf209bdf..3c615035ce 100644 --- a/tests/expectations/tests/libclang-9/objc_template.rs +++ b/tests/expectations/tests/libclang-9/objc_template.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} -pub trait IFoo: Sized + std::ops::Deref { +pub trait IFoo: Sized + std::ops::Deref { unsafe fn get(&self) -> u64 where ::Target: objc::Message + Sized, @@ -35,7 +34,7 @@ pub trait IFoo: Sized + std::ops::Deref { } } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct FooMultiGeneric(pub id); impl std::ops::Deref for FooMultiGeneric { type Target = objc::runtime::Object; @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric { unsafe impl objc::Message for FooMultiGeneric {} impl FooMultiGeneric { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) }) + Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) }) } } impl IFooMultiGeneric for FooMultiGeneric { } -pub trait IFooMultiGeneric: +pub trait IFooMultiGeneric: Sized + std::ops::Deref { unsafe fn objectForKey_(&self, key: u64) -> u64 diff --git a/tests/expectations/tests/objc_allowlist.rs b/tests/expectations/tests/objc_allowlist.rs index dcec0fd12e..370cab9332 100644 --- a/tests/expectations/tests/objc_allowlist.rs +++ b/tests/expectations/tests/objc_allowlist.rs @@ -6,9 +6,53 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; +pub trait PSomeProtocol: Sized + std::ops::Deref { + unsafe fn protocolMethod(&self) + where + ::Target: objc::Message + Sized, + { + msg_send!(*self, protocolMethod) + } + unsafe fn protocolClassMethod() + where + ::Target: objc::Message + Sized, + { + msg_send!(class!(SomeProtocol), protocolClassMethod) + } +} +#[repr(transparent)] +#[derive(Debug, Copy, Clone)] +pub struct AllowlistMe(pub id); +impl std::ops::Deref for AllowlistMe { + type Target = objc::runtime::Object; + fn deref(&self) -> &Self::Target { + unsafe { &*self.0 } + } +} +unsafe impl objc::Message for AllowlistMe {} +impl AllowlistMe { + pub fn alloc() -> Self { + Self(unsafe { msg_send!(class!(AllowlistMe), alloc) }) + } +} +impl PSomeProtocol for AllowlistMe {} +impl IAllowlistMe for AllowlistMe {} +pub trait IAllowlistMe: Sized + std::ops::Deref { + unsafe fn method(&self) + where + ::Target: objc::Message + Sized, + { + msg_send!(*self, method) + } + unsafe fn classMethod() + where + ::Target: objc::Message + Sized, + { + msg_send!(class!(AllowlistMe), classMethod) + } +} impl AllowlistMe_InterestingCategory for AllowlistMe {} pub trait AllowlistMe_InterestingCategory: Sized + std::ops::Deref {} diff --git a/tests/expectations/tests/objc_category.rs b/tests/expectations/tests/objc_category.rs index e0328c708f..9d60233bed 100644 --- a/tests/expectations/tests/objc_category.rs +++ b/tests/expectations/tests/objc_category.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_class.rs b/tests/expectations/tests/objc_class.rs index 5a8a71d164..b322bddcb6 100644 --- a/tests/expectations/tests/objc_class.rs +++ b/tests/expectations/tests/objc_class.rs @@ -6,15 +6,14 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { pub static mut fooVar: Foo; } #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -25,7 +24,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_class_method.rs b/tests/expectations/tests/objc_class_method.rs index 26f2110f43..29e70256ff 100644 --- a/tests/expectations/tests/objc_class_method.rs +++ b/tests/expectations/tests/objc_class_method.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_interface.rs b/tests/expectations/tests/objc_interface.rs index c5ba2758b9..89e64d86b6 100644 --- a/tests/expectations/tests/objc_interface.rs +++ b/tests/expectations/tests/objc_interface.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_interface_type.rs b/tests/expectations/tests/objc_interface_type.rs index cef29c8c96..4ffb15d303 100644 --- a/tests/expectations/tests/objc_interface_type.rs +++ b/tests/expectations/tests/objc_interface_type.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_method.rs b/tests/expectations/tests/objc_method.rs index af5c6093db..593fd27738 100644 --- a/tests/expectations/tests/objc_method.rs +++ b/tests/expectations/tests/objc_method.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_method_clash.rs b/tests/expectations/tests/objc_method_clash.rs index 8370f33fc2..ac77cc19e3 100644 --- a/tests/expectations/tests/objc_method_clash.rs +++ b/tests/expectations/tests/objc_method_clash.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_pointer_return_types.rs b/tests/expectations/tests/objc_pointer_return_types.rs index c9b6b52a6b..1ec8494d25 100644 --- a/tests/expectations/tests/objc_pointer_return_types.rs +++ b/tests/expectations/tests/objc_pointer_return_types.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -22,13 +21,13 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IBar for Bar {} pub trait IBar: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -39,7 +38,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_property_fnptr.rs b/tests/expectations/tests/objc_property_fnptr.rs index 85f18e9c18..9f3fabd272 100644 --- a/tests/expectations/tests/objc_property_fnptr.rs +++ b/tests/expectations/tests/objc_property_fnptr.rs @@ -6,12 +6,11 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -22,7 +21,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl IFoo for Foo {} diff --git a/tests/expectations/tests/objc_protocol.rs b/tests/expectations/tests/objc_protocol.rs index e68ddcc1d2..5bd7d433f4 100644 --- a/tests/expectations/tests/objc_protocol.rs +++ b/tests/expectations/tests/objc_protocol.rs @@ -6,13 +6,12 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -23,7 +22,7 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl PFoo for Foo {} diff --git a/tests/expectations/tests/objc_protocol_inheritance.rs b/tests/expectations/tests/objc_protocol_inheritance.rs index 598273ba35..f5f80e2e30 100644 --- a/tests/expectations/tests/objc_protocol_inheritance.rs +++ b/tests/expectations/tests/objc_protocol_inheritance.rs @@ -6,13 +6,12 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; pub trait PFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Foo(pub id); impl std::ops::Deref for Foo { type Target = objc::runtime::Object; @@ -23,14 +22,14 @@ impl std::ops::Deref for Foo { unsafe impl objc::Message for Foo {} impl Foo { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Foo), alloc) }) + Self(unsafe { msg_send!(class!(Foo), alloc) }) } } impl PFoo for Foo {} impl IFoo for Foo {} pub trait IFoo: Sized + std::ops::Deref {} #[repr(transparent)] -#[derive(Clone)] +#[derive(Debug, Copy, Clone)] pub struct Bar(pub id); impl std::ops::Deref for Bar { type Target = objc::runtime::Object; @@ -41,7 +40,7 @@ impl std::ops::Deref for Bar { unsafe impl objc::Message for Bar {} impl Bar { pub fn alloc() -> Self { - Self(unsafe { msg_send!(objc::class!(Bar), alloc) }) + Self(unsafe { msg_send!(class!(Bar), alloc) }) } } impl IFoo for Bar {} diff --git a/tests/expectations/tests/objc_sel_and_id.rs b/tests/expectations/tests/objc_sel_and_id.rs index 2a389093df..0017eab00d 100644 --- a/tests/expectations/tests/objc_sel_and_id.rs +++ b/tests/expectations/tests/objc_sel_and_id.rs @@ -6,8 +6,7 @@ )] #![cfg(target_os = "macos")] -#[macro_use] -extern crate objc; +use objc::{self, class, msg_send, sel, sel_impl}; #[allow(non_camel_case_types)] pub type id = *mut objc::runtime::Object; extern "C" { diff --git a/tests/headers/objc_allowlist.h b/tests/headers/objc_allowlist.h index 8c939960b0..b5406d0adf 100644 --- a/tests/headers/objc_allowlist.h +++ b/tests/headers/objc_allowlist.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate --allowlist-type AllowlistMe --allowlist-type AllowlistMe_InterestingCategory -- -x objective-c +// bindgen-flags: --allowlist-type IAllowlistMe --allowlist-type AllowlistMe_InterestingCategory -- -x objective-c // bindgen-osx-only diff --git a/tests/headers/objc_category.h b/tests/headers/objc_category.h index c464b72eb2..b8e60d5fa9 100644 --- a/tests/headers/objc_category.h +++ b/tests/headers/objc_category.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_class.h b/tests/headers/objc_class.h index cea72e78aa..f5ec950750 100644 --- a/tests/headers/objc_class.h +++ b/tests/headers/objc_class.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @class Foo; diff --git a/tests/headers/objc_class_method.h b/tests/headers/objc_class_method.h index ddda742e8a..1a68ed3e6e 100644 --- a/tests/headers/objc_class_method.h +++ b/tests/headers/objc_class_method.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_inheritance.h b/tests/headers/objc_inheritance.h index 8f96e45ba8..985f1597e5 100644 --- a/tests/headers/objc_inheritance.h +++ b/tests/headers/objc_inheritance.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_interface.h b/tests/headers/objc_interface.h index af84bf925a..df16e921ec 100644 --- a/tests/headers/objc_interface.h +++ b/tests/headers/objc_interface.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_interface_type.h b/tests/headers/objc_interface_type.h index 31d33664c1..4667ce2a0c 100644 --- a/tests/headers/objc_interface_type.h +++ b/tests/headers/objc_interface_type.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_method.h b/tests/headers/objc_method.h index c4d375bac0..b89d1621b1 100644 --- a/tests/headers/objc_method.h +++ b/tests/headers/objc_method.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_method_clash.h b/tests/headers/objc_method_clash.h index a56e39dba8..d99d3691fe 100644 --- a/tests/headers/objc_method_clash.h +++ b/tests/headers/objc_method_clash.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_pointer_return_types.h b/tests/headers/objc_pointer_return_types.h index e289a8a53d..4d1a6dea34 100644 --- a/tests/headers/objc_pointer_return_types.h +++ b/tests/headers/objc_pointer_return_types.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Bar diff --git a/tests/headers/objc_property_fnptr.h b/tests/headers/objc_property_fnptr.h index bac0c779a9..fe3e7fcc99 100644 --- a/tests/headers/objc_property_fnptr.h +++ b/tests/headers/objc_property_fnptr.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo diff --git a/tests/headers/objc_protocol.h b/tests/headers/objc_protocol.h index 0c760fa51f..46978a3b4e 100644 --- a/tests/headers/objc_protocol.h +++ b/tests/headers/objc_protocol.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @protocol Foo diff --git a/tests/headers/objc_protocol_inheritance.h b/tests/headers/objc_protocol_inheritance.h index d5f3a490e5..13135fddbc 100644 --- a/tests/headers/objc_protocol_inheritance.h +++ b/tests/headers/objc_protocol_inheritance.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @protocol Foo diff --git a/tests/headers/objc_sel_and_id.h b/tests/headers/objc_sel_and_id.h index 3c8c656166..6491a541c6 100644 --- a/tests/headers/objc_sel_and_id.h +++ b/tests/headers/objc_sel_and_id.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only id object; diff --git a/tests/headers/objc_template.h b/tests/headers/objc_template.h index a4d0055c16..b616da013f 100644 --- a/tests/headers/objc_template.h +++ b/tests/headers/objc_template.h @@ -1,4 +1,4 @@ -// bindgen-flags: --objc-extern-crate -- -x objective-c +// bindgen-flags: -- -x objective-c // bindgen-osx-only @interface Foo<__covariant ObjectType>