Skip to content

Commit 053fb1d

Browse files
author
bors-servo
authored
Auto merge of #1026 - alexeyzab:fix-compiling-expectations-macos, r=fitzgen
Make objc-related expectations compile Fixes #1004. After looking at how `msg_send!` is supposed to be used, I realized that we were erroneously passing type signatures to it. The expectations compile now, but some of them are not formatted properly. My guess is that `rustfmt` does not know how to format the following: ``` msg_send!(obj, arg1:1 arg2:2 arg3:3) ``` Notice the lack of separatros between the `arg`s. Any advice on how to proceed here is appreciated. r? @fitzgen
2 parents 4140c96 + ca0aa04 commit 053fb1d

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

src/ir/objc.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,21 @@ impl ObjCMethod {
236236
);
237237
}
238238

239+
// Get arguments without type signatures to pass to `msg_send!`
240+
let mut args_without_types = vec![];
241+
for arg in args.iter() {
242+
let name_and_sig: Vec<&str> = arg.as_str().split(' ').collect();
243+
let name = name_and_sig[0];
244+
args_without_types.push(quote::Ident::new(name))
245+
};
246+
239247
let args = split_name
240248
.into_iter()
241-
.zip(args.iter())
242-
.map(|(arg, ty)| quote! { #arg : #ty });
249+
.zip(args_without_types)
250+
.map(|(arg, arg_val)| quote! { #arg : #arg_val });
243251

244252
quote! {
245-
#( #args ),*
253+
#( #args )*
246254
}
247255
}
248256
}

tests/expectations/tests/objc_class_method.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ impl Foo for id {
3030
unsafe fn methodWithInt_(foo: ::std::os::raw::c_int) {
3131
msg_send!(
3232
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
33-
methodWithInt: foo: ::std::os::raw::c_int
33+
methodWithInt: foo
3434
)
3535
}
3636
unsafe fn methodWithFoo_(foo: id) {
3737
msg_send!(
3838
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
39-
methodWithFoo: foo: id
39+
methodWithFoo: foo
4040
)
4141
}
4242
unsafe fn methodReturningInt() -> ::std::os::raw::c_int {
@@ -56,11 +56,6 @@ impl Foo for id {
5656
ptr: *mut ::std::os::raw::c_char,
5757
floatvalue: f32,
5858
) {
59-
msg_send!(
60-
objc::runtime::Class::get("Foo").expect("Couldn't find Foo"),
61-
methodWithArg1: intvalue: ::std::os::raw::c_int,
62-
andArg2: ptr: *mut ::std::os::raw::c_char,
63-
andArg3: floatvalue: f32
64-
)
59+
msg_send ! ( objc :: runtime :: Class :: get ( "Foo" ) . expect ( "Couldn't find Foo" ) , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
6560
}
6661
}

tests/expectations/tests/objc_method.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ impl Foo for id {
2626
msg_send!(self, method)
2727
}
2828
unsafe fn methodWithInt_(self, foo: ::std::os::raw::c_int) {
29-
msg_send!(self, methodWithInt: foo: ::std::os::raw::c_int)
29+
msg_send!(self, methodWithInt: foo)
3030
}
3131
unsafe fn methodWithFoo_(self, foo: id) {
32-
msg_send!(self, methodWithFoo: foo: id)
32+
msg_send!(self, methodWithFoo: foo)
3333
}
3434
unsafe fn methodReturningInt(self) -> ::std::os::raw::c_int {
3535
msg_send!(self, methodReturningInt)
@@ -43,11 +43,6 @@ impl Foo for id {
4343
ptr: *mut ::std::os::raw::c_char,
4444
floatvalue: f32,
4545
) {
46-
msg_send!(
47-
self,
48-
methodWithArg1: intvalue: ::std::os::raw::c_int,
49-
andArg2: ptr: *mut ::std::os::raw::c_char,
50-
andArg3: floatvalue: f32
51-
)
46+
msg_send ! ( self , methodWithArg1 : intvalue andArg2 : ptr andArg3 : floatvalue )
5247
}
5348
}

tests/expectations/tests/objc_property_fnptr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ impl Foo for id {
2323
self,
2424
func: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>,
2525
) {
26-
msg_send!(
27-
self,
28-
setFunc: func: ::std::option::Option<unsafe extern "C" fn() -> ::std::os::raw::c_int>
29-
)
26+
msg_send!(self, setFunc: func)
3027
}
3128
}

0 commit comments

Comments
 (0)