rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Objective-C method fragment needs keyword escape

Open youknowone opened this issue 3 years ago • 1 comments

Input C/C++ Header

@interface A
-(void)f:(int)arg1 as:(int)arg2;
@end

Bindgen Invocation

$ bindgen objc_escape.m 

Actual Results

/* automatically generated by rust-bindgen 0.60.1 */

use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Debug, Copy, Clone)]
pub struct A(pub id);
impl std::ops::Deref for A {
    type Target = objc::runtime::Object;
    fn deref(&self) -> &Self::Target {
        unsafe { &*self.0 }
    }
}
unsafe impl objc::Message for A {}
impl A {
    pub fn alloc() -> Self {
        Self(unsafe { msg_send!(class!(A), alloc) })
    }
}
impl IA for A {}
pub trait IA: Sized + std::ops::Deref {
    unsafe fn f_as_(&self, arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int)
    where
        <Self as std::ops::Deref>::Target: objc::Message + Sized,
    {
        msg_send ! (* self , f : arg1 as : arg2)
    }
}

as part in msg_send! will be keyword error.

Expected Results

use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Debug, Copy, Clone)]
pub struct A(pub id);
impl std::ops::Deref for A {
    type Target = objc::runtime::Object;
    fn deref(&self) -> &Self::Target {
        unsafe { &*self.0 }
    }
}
unsafe impl objc::Message for A {}
impl A {
    pub fn alloc() -> Self {
        Self(unsafe { msg_send!(class!(A), alloc) })
    }
}
impl IA for A {}
pub trait IA: Sized + std::ops::Deref {
    unsafe fn f_as_(&self, arg1: ::std::os::raw::c_int, arg2: ::std::os::raw::c_int)
    where
        <Self as std::ops::Deref>::Target: objc::Message + Sized,
    {
        msg_send ! (* self , f : arg1 r#as : arg2)
    }
}

escaping with r#as will fix compile error

youknowone avatar Jul 22 '22 00:07 youknowone

Should be trivial-ish to do this I think, thanks for the report!

emilio avatar Jul 25 '22 09:07 emilio