Skip to content

Commit 125917f

Browse files
authored
Merge pull request #233 from dtolnay/reference
Bypass Sync bound implied by non-existent drop of reference
2 parents d71c74d + ba93025 commit 125917f

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/expand.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,16 @@ fn transform_sig(
297297
}) => {}
298298
FnArg::Receiver(arg) => arg.mutability = None,
299299
FnArg::Typed(arg) => {
300-
if let Pat::Ident(ident) = &mut *arg.pat {
301-
ident.by_ref = None;
302-
ident.mutability = None;
303-
} else {
300+
let type_is_reference = match *arg.ty {
301+
Type::Reference(_) => true,
302+
_ => false,
303+
};
304+
if let Pat::Ident(pat) = &mut *arg.pat {
305+
if pat.ident == "self" || !type_is_reference {
306+
pat.by_ref = None;
307+
pat.mutability = None;
308+
}
309+
} else if !type_is_reference {
304310
let positional = positional_arg(i, &arg.pat);
305311
let m = mut_pat(&mut arg.pat);
306312
arg.pat = parse_quote!(#m #positional);
@@ -376,12 +382,16 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
376382
self_span = Some(ident.span());
377383
let prefixed = Ident::new("__self", ident.span());
378384
quote!(let #mutability #prefixed = #ident;)
385+
} else if let Type::Reference(_) = *arg.ty {
386+
quote!()
379387
} else {
380388
quote! {
381389
#(#attrs)*
382390
let #mutability #ident = #ident;
383391
}
384392
}
393+
} else if let Type::Reference(_) = *arg.ty {
394+
quote!()
385395
} else {
386396
let pat = &arg.pat;
387397
let ident = positional_arg(i, pat);

tests/test.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,3 +1489,37 @@ pub mod issue226 {
14891489
}
14901490
}
14911491
}
1492+
1493+
// https://github.com/dtolnay/async-trait/issues/232
1494+
pub mod issue232 {
1495+
use async_trait::async_trait;
1496+
1497+
#[async_trait]
1498+
pub trait Generic<T> {
1499+
async fn take_ref(&self, thing: &T);
1500+
}
1501+
1502+
pub struct One;
1503+
1504+
#[async_trait]
1505+
impl<T> Generic<T> for One {
1506+
async fn take_ref(&self, _: &T) {}
1507+
}
1508+
1509+
pub struct Two;
1510+
1511+
#[async_trait]
1512+
impl<T: Sync> Generic<(T, T)> for Two {
1513+
async fn take_ref(&self, (a, b): &(T, T)) {
1514+
let _ = a;
1515+
let _ = b;
1516+
}
1517+
}
1518+
1519+
pub struct Three;
1520+
1521+
#[async_trait]
1522+
impl<T> Generic<(T, T, T)> for Three {
1523+
async fn take_ref(&self, (_a, _b, _c): &(T, T, T)) {}
1524+
}
1525+
}

0 commit comments

Comments
 (0)