Skip to content

Commit f51435a

Browse files
committed
Fix CI attempt 2
1 parent 3ab1350 commit f51435a

File tree

5 files changed

+195
-54
lines changed

5 files changed

+195
-54
lines changed

src/codegen/mod.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,16 +3394,12 @@ impl TryToRustTy for Type {
33943394
TypeKind::ObjCSel => Ok(quote! {
33953395
objc::runtime::Sel
33963396
}),
3397-
TypeKind::ObjCId => {
3398-
Ok(quote! {
3399-
id
3400-
})
3401-
}
3402-
TypeKind::ObjCInterface(..) => {
3403-
Ok(quote! {
3404-
objc::runtime::Object
3405-
})
3406-
}
3397+
TypeKind::ObjCId => Ok(quote! {
3398+
id
3399+
}),
3400+
TypeKind::ObjCInterface(..) => Ok(quote! {
3401+
objc::runtime::Object
3402+
}),
34073403
ref u @ TypeKind::UnresolvedTypeRef(..) => {
34083404
unreachable!("Should have been resolved after parsing {:?}!", u)
34093405
}
@@ -3663,7 +3659,7 @@ fn objc_method_codegen(
36633659
}
36643660
} else {
36653661
let fn_args = fn_args.clone();
3666-
let args = iter::once(quote!{ self }).chain(fn_args.into_iter());
3662+
let args = iter::once(quote! { self }).chain(fn_args.into_iter());
36673663
quote! {
36683664
( #( #args ),* ) #fn_ret
36693665
}
@@ -3672,9 +3668,11 @@ fn objc_method_codegen(
36723668
let methods_and_args = method.format_method_call(&fn_args);
36733669

36743670
let body = if method.is_class_method() {
3675-
let class_name = ctx.rust_ident(class_name
3676-
.expect("Generating a class method without class name?")
3677-
.to_owned());
3671+
let class_name = ctx.rust_ident(
3672+
class_name
3673+
.expect("Generating a class method without class name?")
3674+
.to_owned(),
3675+
);
36783676
quote! {
36793677
msg_send!(class!(#class_name), #methods_and_args)
36803678
}
@@ -3684,7 +3682,8 @@ fn objc_method_codegen(
36843682
}
36853683
};
36863684

3687-
let method_name = ctx.rust_ident(format!("{}{}", prefix, method.rust_name()));
3685+
let method_name =
3686+
ctx.rust_ident(format!("{}{}", prefix, method.rust_name()));
36883687

36893688
quote! {
36903689
unsafe fn #method_name #sig where <Self as std::ops::Deref>::Target: objc::Message + Sized {
@@ -3707,8 +3706,7 @@ impl CodeGenerator for ObjCInterface {
37073706
let mut impl_items = vec![];
37083707

37093708
for method in self.methods() {
3710-
let impl_item =
3711-
objc_method_codegen(ctx, method, None, "");
3709+
let impl_item = objc_method_codegen(ctx, method, None, "");
37123710
impl_items.push(impl_item);
37133711
}
37143712

@@ -3778,8 +3776,11 @@ impl CodeGenerator for ObjCInterface {
37783776
};
37793777
result.push(struct_block);
37803778
for protocol_id in self.conforms_to.iter() {
3781-
let protocol_name =
3782-
ctx.rust_ident(ctx.resolve_type(protocol_id.expect_type_id(ctx)).name().unwrap());
3779+
let protocol_name = ctx.rust_ident(
3780+
ctx.resolve_type(protocol_id.expect_type_id(ctx))
3781+
.name()
3782+
.unwrap(),
3783+
);
37833784
let impl_trait = quote! {
37843785
impl #protocol_name for #struct_name { }
37853786
};

tests/expectations/tests/libclang-3.8/objc_template.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,56 @@
88
extern crate objc;
99
#[allow(non_camel_case_types)]
1010
pub type id = *mut objc::runtime::Object;
11-
pub trait Foo<ObjectType> {
12-
unsafe fn get(self) -> id;
11+
#[repr(transparent)]
12+
#[derive(Clone, Copy)]
13+
pub struct Foo(pub id);
14+
impl std::ops::Deref for Foo {
15+
type Target = objc::runtime::Object;
16+
fn deref(&self) -> &Self::Target {
17+
unsafe { &*self.0 }
18+
}
19+
}
20+
unsafe impl objc::Message for Foo {}
21+
impl Foo {
22+
pub fn alloc() -> Self {
23+
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
}
1325
}
14-
impl<ObjectType: 'static> Foo<ObjectType> for id {
15-
unsafe fn get(self) -> id {
26+
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
27+
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
28+
unsafe fn get(self) -> id
29+
where
30+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
31+
{
1632
msg_send!(self, get)
1733
}
1834
}
19-
pub trait FooMultiGeneric<KeyType, ObjectType> {
20-
unsafe fn objectForKey_(self, key: id) -> id;
35+
#[repr(transparent)]
36+
#[derive(Clone, Copy)]
37+
pub struct FooMultiGeneric(pub id);
38+
impl std::ops::Deref for FooMultiGeneric {
39+
type Target = objc::runtime::Object;
40+
fn deref(&self) -> &Self::Target {
41+
unsafe { &*self.0 }
42+
}
43+
}
44+
unsafe impl objc::Message for FooMultiGeneric {}
45+
impl FooMultiGeneric {
46+
pub fn alloc() -> Self {
47+
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
48+
}
49+
}
50+
impl<KeyType: 'static, ObjectType: 'static>
51+
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
52+
{
2153
}
22-
impl<KeyType: 'static, ObjectType: 'static> FooMultiGeneric<KeyType, ObjectType>
23-
for id
54+
pub trait IFooMultiGeneric<KeyType, ObjectType>:
55+
Sized + std::ops::Deref
2456
{
25-
unsafe fn objectForKey_(self, key: id) -> id {
57+
unsafe fn objectForKey_(self, key: id) -> id
58+
where
59+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
60+
{
2661
msg_send!(self, objectForKey: key)
2762
}
2863
}

tests/expectations/tests/libclang-3.9/objc_template.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,56 @@
88
extern crate objc;
99
#[allow(non_camel_case_types)]
1010
pub type id = *mut objc::runtime::Object;
11-
pub trait Foo<ObjectType> {
12-
unsafe fn get(self) -> id;
11+
#[repr(transparent)]
12+
#[derive(Clone, Copy)]
13+
pub struct Foo(pub id);
14+
impl std::ops::Deref for Foo {
15+
type Target = objc::runtime::Object;
16+
fn deref(&self) -> &Self::Target {
17+
unsafe { &*self.0 }
18+
}
19+
}
20+
unsafe impl objc::Message for Foo {}
21+
impl Foo {
22+
pub fn alloc() -> Self {
23+
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
}
1325
}
14-
impl<ObjectType: 'static> Foo<ObjectType> for id {
15-
unsafe fn get(self) -> id {
26+
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
27+
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
28+
unsafe fn get(self) -> id
29+
where
30+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
31+
{
1632
msg_send!(self, get)
1733
}
1834
}
19-
pub trait FooMultiGeneric<KeyType, ObjectType> {
20-
unsafe fn objectForKey_(self, key: id) -> id;
35+
#[repr(transparent)]
36+
#[derive(Clone, Copy)]
37+
pub struct FooMultiGeneric(pub id);
38+
impl std::ops::Deref for FooMultiGeneric {
39+
type Target = objc::runtime::Object;
40+
fn deref(&self) -> &Self::Target {
41+
unsafe { &*self.0 }
42+
}
43+
}
44+
unsafe impl objc::Message for FooMultiGeneric {}
45+
impl FooMultiGeneric {
46+
pub fn alloc() -> Self {
47+
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
48+
}
49+
}
50+
impl<KeyType: 'static, ObjectType: 'static>
51+
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
52+
{
2153
}
22-
impl<KeyType: 'static, ObjectType: 'static> FooMultiGeneric<KeyType, ObjectType>
23-
for id
54+
pub trait IFooMultiGeneric<KeyType, ObjectType>:
55+
Sized + std::ops::Deref
2456
{
25-
unsafe fn objectForKey_(self, key: id) -> id {
57+
unsafe fn objectForKey_(self, key: id) -> id
58+
where
59+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
60+
{
2661
msg_send!(self, objectForKey: key)
2762
}
2863
}

tests/expectations/tests/libclang-4/objc_template.rs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,55 @@
99
extern crate objc;
1010
#[allow(non_camel_case_types)]
1111
pub type id = *mut objc::runtime::Object;
12-
pub trait Foo<ObjectType> {
13-
unsafe fn get(self)
14-
-> *mut ObjectType;
12+
#[repr(transparent)]
13+
#[derive(Clone, Copy)]
14+
pub struct Foo(pub id);
15+
impl std::ops::Deref for Foo {
16+
type Target = objc::runtime::Object;
17+
fn deref(&self) -> &Self::Target {
18+
unsafe { &*self.0 }
19+
}
20+
}
21+
unsafe impl objc::Message for Foo {}
22+
impl Foo {
23+
pub fn alloc() -> Self {
24+
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
25+
}
1526
}
16-
impl<ObjectType: 'static> Foo<ObjectType> for id {
27+
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
28+
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
29+
unsafe fn get(self) -> *mut ObjectType
30+
where
31+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
32+
{
1733
unsafe fn get(self) -> *mut ObjectType { msg_send!(self , get) }
1834
}
19-
pub trait FooMultiGeneric<KeyType, ObjectType> {
20-
unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType;
35+
#[repr(transparent)]
36+
#[derive(Clone, Copy)]
37+
pub struct FooMultiGeneric(pub id);
38+
impl std::ops::Deref for FooMultiGeneric {
39+
type Target = objc::runtime::Object;
40+
fn deref(&self) -> &Self::Target {
41+
unsafe { &*self.0 }
42+
}
43+
}
44+
unsafe impl objc::Message for FooMultiGeneric {}
45+
impl FooMultiGeneric {
46+
pub fn alloc() -> Self {
47+
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
48+
}
49+
}
50+
impl<KeyType: 'static, ObjectType: 'static>
51+
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
52+
{
2153
}
22-
impl<KeyType: 'static, ObjectType: 'static> FooMultiGeneric<KeyType, ObjectType>
23-
for id
54+
pub trait IFooMultiGeneric<KeyType, ObjectType>:
55+
Sized + std::ops::Deref
2456
{
57+
unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType
58+
where
59+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
60+
{
2561
unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType {
2662
msg_send!(self, objectForKey: key)
2763
}

tests/expectations/tests/libclang-5/objc_template.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,55 @@
1212
extern crate objc;
1313
#[allow(non_camel_case_types)]
1414
pub type id = *mut objc::runtime::Object;
15-
pub trait Foo<ObjectType> {
16-
unsafe fn get(self) -> *mut ObjectType;
15+
#[repr(transparent)]
16+
#[derive(Clone, Copy)]
17+
pub struct Foo(pub id);
18+
impl std::ops::Deref for Foo {
19+
type Target = objc::runtime::Object;
20+
fn deref(&self) -> &Self::Target {
21+
unsafe { &*self.0 }
22+
}
23+
}
24+
unsafe impl objc::Message for Foo {}
25+
impl Foo {
26+
pub fn alloc() -> Self {
27+
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
28+
}
1729
}
18-
impl<ObjectType: 'static> Foo<ObjectType> for id {
19-
unsafe fn get(self) -> *mut ObjectType {
30+
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
31+
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
32+
unsafe fn get(self) -> *mut ObjectType
33+
where
34+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
35+
{
2036
msg_send!(self, get)
2137
}
2238
}
23-
pub trait FooMultiGeneric<KeyType, ObjectType> {
24-
unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType;
39+
#[repr(transparent)]
40+
#[derive(Clone, Copy)]
41+
pub struct FooMultiGeneric(pub id);
42+
impl std::ops::Deref for FooMultiGeneric {
43+
type Target = objc::runtime::Object;
44+
fn deref(&self) -> &Self::Target {
45+
unsafe { &*self.0 }
46+
}
47+
}
48+
unsafe impl objc::Message for FooMultiGeneric {}
49+
impl FooMultiGeneric {
50+
pub fn alloc() -> Self {
51+
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
52+
}
53+
}
54+
impl<KeyType: 'static, ObjectType: 'static>
55+
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
56+
{
2557
}
26-
impl<KeyType: 'static, ObjectType: 'static> FooMultiGeneric<KeyType, ObjectType>
27-
for id
58+
pub trait IFooMultiGeneric<KeyType, ObjectType>:
59+
Sized + std::ops::Deref
2860
{
29-
unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType {
61+
unsafe fn objectForKey_(self, key: *mut KeyType) -> *mut ObjectType
62+
where
63+
<Self as std::ops::Deref>::Target: objc::Message + Sized,
3064
msg_send!(self, objectForKey: key)
3165
}
3266
}

0 commit comments

Comments
 (0)