let mut first_arg = true;
let mut num_unused = 0;
for inp in sig.inputs.iter() {
+ let mut handle_self = |is_ref: bool, is_mut: bool| {
+ write!(w, "{}this_arg: {}{}", if !is_ref { "mut " } else { "" },
+ if is_ref {
+ match (self_ptr, is_mut) {
+ (true, true) => "*mut ",
+ (true, false) => "*const ",
+ (false, true) => "&mut ",
+ (false, false) => "&",
+ }
+ } else { "" }, this_param).unwrap();
+ assert!(first_arg);
+ first_arg = false;
+ };
match inp {
syn::FnArg::Receiver(recv) => {
if !recv.attrs.is_empty() { unimplemented!(); }
- write!(w, "{}this_arg: {}{}", if recv.reference.is_none() { "mut " } else { "" },
- if recv.reference.is_some() {
- match (self_ptr, recv.mutability.is_some()) {
- (true, true) => "*mut ",
- (true, false) => "*const ",
- (false, true) => "&mut ",
- (false, false) => "&",
- }
- } else { "" }, this_param).unwrap();
- assert!(first_arg);
- first_arg = false;
+ handle_self(recv.reference.is_some(), recv.mutability.is_some());
},
syn::FnArg::Typed(arg) => {
+ if let syn::Pat::Ident(id) = &*arg.pat {
+ if format!("{}", id.ident) == "self" {
+ handle_self(id.by_ref.is_some(), id.mutability.is_some());
+ continue;
+ }
+ }
+
if types.skip_arg(&*arg.ty, generics) { continue; }
if !arg.attrs.is_empty() { unimplemented!(); }
// First get the c type so that we can check if it ends up being a reference:
match inp {
syn::FnArg::Receiver(_) => {},
syn::FnArg::Typed(arg) => {
+ if let syn::Pat::Ident(id) = &*arg.pat {
+ if format!("{}", id.ident) == "self" {
+ continue;
+ }
+ }
+
if types.skip_arg(&*arg.ty, generics) { continue; }
if !arg.attrs.is_empty() { unimplemented!(); }
macro_rules! write_new_var {
}
},
syn::FnArg::Typed(arg) => {
+ if let syn::Pat::Ident(id) = &*arg.pat {
+ if format!("{}", id.ident) == "self" {
+ if to_c {
+ if id.by_ref.is_none() && !matches!(&*arg.ty, syn::Type::Reference(_)) { unimplemented!(); }
+ write!(w, "self.this_arg").unwrap();
+ first_arg = false;
+ }
+ continue;
+ }
+ }
+
if types.skip_arg(&*arg.ty, generics) {
if !to_c {
if !first_arg {
write_method_var_decl_body(w, &$trait_meth.sig, "", &mut trait_resolver, Some(&meth_gen_types), false);
let mut takes_self = false;
for inp in $m.sig.inputs.iter() {
- if let syn::FnArg::Receiver(_) = inp {
- takes_self = true;
+ match inp {
+ syn::FnArg::Receiver(_) => {
+ takes_self = true;
+ break;
+ },
+ syn::FnArg::Typed(ty) => {
+ if let syn::Pat::Ident(id) = &*ty.pat {
+ if format!("{}", id.ident) == "self" {
+ takes_self = true;
+ break;
+ }
+ }
+ }
}
}
let mut takes_mut_self = false;
let mut takes_owned_self = false;
for inp in m.sig.inputs.iter() {
- if let syn::FnArg::Receiver(r) = inp {
- takes_self = true;
- if r.mutability.is_some() { takes_mut_self = true; }
- if r.reference.is_none() { takes_owned_self = true; }
+ match inp {
+ syn::FnArg::Receiver(r) => {
+ takes_self = true;
+ if r.mutability.is_some() { takes_mut_self = true; }
+ if r.reference.is_none() { takes_owned_self = true; }
+ break;
+ },
+ syn::FnArg::Typed(ty) => {
+ if let syn::Pat::Ident(id) = &*ty.pat {
+ if format!("{}", id.ident) == "self" {
+ takes_self = true;
+ if id.mutability.is_some() { takes_mut_self = true; }
+ if id.by_ref.is_none() { takes_owned_self = true; }
+ break;
+ }
+ }
+ }
}
}
if !takes_mut_self && !takes_self {