Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
async fn take_ref(&self, thing: &T);
}

pub struct One;

#[async_trait]
impl<T> Generic<T> for One {
async fn take_ref(&self, _: &T) {}
}

pub struct Two;

#[async_trait]
impl<T: Sync> Generic<(T, T)> for Two {
async fn take_ref(&self, (a, b): &(T, T)) {
let _ = a;
let _ = b;
}
}

pub struct Three;

#[async_trait]
impl<T> Generic<(T, T, T)> for Three {
async fn take_ref(&self, (_a, _b, _c): &(T, T, T)) {}
}
}