diff --git a/src/expand.rs b/src/expand.rs index 3fdcb51..7747e68 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -297,10 +297,16 @@ fn transform_sig( }) => {} FnArg::Receiver(arg) => arg.mutability = None, FnArg::Typed(arg) => { - if let Pat::Ident(ident) = &mut *arg.pat { - ident.by_ref = None; - ident.mutability = None; - } else { + let type_is_reference = match *arg.ty { + Type::Reference(_) => true, + _ => false, + }; + if let Pat::Ident(pat) = &mut *arg.pat { + if pat.ident == "self" || !type_is_reference { + pat.by_ref = None; + pat.mutability = None; + } + } else if !type_is_reference { let positional = positional_arg(i, &arg.pat); let m = mut_pat(&mut arg.pat); arg.pat = parse_quote!(#m #positional); @@ -376,12 +382,16 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) { self_span = Some(ident.span()); let prefixed = Ident::new("__self", ident.span()); quote!(let #mutability #prefixed = #ident;) + } else if let Type::Reference(_) = *arg.ty { + quote!() } else { quote! { #(#attrs)* let #mutability #ident = #ident; } } + } else if let Type::Reference(_) = *arg.ty { + quote!() } else { let pat = &arg.pat; let ident = positional_arg(i, pat); diff --git a/tests/test.rs b/tests/test.rs index 3982638..211387a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1489,3 +1489,37 @@ pub mod issue226 { } } } + +// https://github.com/dtolnay/async-trait/issues/232 +pub mod issue232 { + use async_trait::async_trait; + + #[async_trait] + pub trait Generic { + async fn take_ref(&self, thing: &T); + } + + pub struct One; + + #[async_trait] + impl Generic for One { + async fn take_ref(&self, _: &T) {} + } + + pub struct Two; + + #[async_trait] + impl Generic<(T, T)> for Two { + async fn take_ref(&self, (a, b): &(T, T)) { + let _ = a; + let _ = b; + } + } + + pub struct Three; + + #[async_trait] + impl Generic<(T, T, T)> for Three { + async fn take_ref(&self, (_a, _b, _c): &(T, T, T)) {} + } +}