Support wildcard arguments in foreign functions (#351)

No real reason to not support them!

Closes #346
This commit is contained in:
Alex Crichton
2018-06-28 20:06:35 -05:00
committed by GitHub
parent 37293ee42a
commit 4138583dff
2 changed files with 40 additions and 6 deletions

View File

@ -573,6 +573,7 @@ impl ToTokens for ast::ImportFunction {
let mut abi_argument_names = Vec::new();
let mut abi_arguments = Vec::new();
let mut arg_conversions = Vec::new();
let mut arguments = Vec::new();
let ret_ident = Ident::new("_ret", Span::call_site());
for (i, syn::ArgCaptured { pat, ty, .. }) in self.function.arguments.iter().enumerate() {
@ -583,6 +584,9 @@ impl ToTokens for ast::ImportFunction {
subpat: None,
..
}) => ident.clone(),
syn::Pat::Wild(_) => {
syn::Ident::new(&format!("__genarg_{}", i), Span::call_site())
}
_ => panic!("unsupported pattern in foreign function"),
};
@ -593,6 +597,7 @@ impl ToTokens for ast::ImportFunction {
let var = if i == 0 && is_method {
quote! { self }
} else {
arguments.push(quote! { #name: #ty });
quote! { #name }
};
arg_conversions.push(quote! {
@ -651,12 +656,7 @@ impl ToTokens for ast::ImportFunction {
let rust_name = &self.rust_name;
let import_name = &self.shim;
let attrs = &self.function.rust_attrs;
let arguments = if is_method {
&self.function.arguments[1..]
} else {
&self.function.arguments[..]
};
let arguments = &arguments;
let me = if is_method {
quote! { &self, }