Skip to content

Commit 70bf4b0

Browse files
committed
Add regression test for issue 232
Currently fails to compile: error: future cannot be sent between threads safely --> tests/test.rs:1506:41 | 1506 | async fn take_ref(&self, _: &T) {} | ^^ future created by async block is not `Send` | note: captured value is not `Send` because `&` references cannot be sent unless their referent is `Sync` --> tests/test.rs:1506:34 | 1504 | #[async_trait] | -------------- in this procedural macro expansion 1505 | impl<T> Generic<T> for One { 1506 | async fn take_ref(&self, _: &T) {} | ^ has type `&T` which is not `Send`, because `T` is not `Sync` = note: required for the cast from `[async block@tests/test.rs:1506:41: 1506:43]` to the object type `dyn futures::Future<Output = ()> + std::marker::Send` = note: this error originates in the attribute macro `async_trait` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider restricting type parameter `T` | 1505 | impl<T: std::marker::Sync> Generic<T> for One { | +++++++++++++++++++ error[E0277]: `T` cannot be shared between threads safely --> tests/test.rs:1523:60 | 1523 | async fn take_ref(&self, (_a, _b, _c): &(T, T, T)) {} | ^^ `T` cannot be shared between threads safely | = note: required because it appears within the type `(T, T, T)` = note: required for `&(T, T, T)` to implement `std::marker::Send` note: required because it's used within this `async` block --> tests/test.rs:1523:60 | 1523 | async fn take_ref(&self, (_a, _b, _c): &(T, T, T)) {} | ^^ = note: required for the cast from `[async block@tests/test.rs:1523:60: 1523:62]` to the object type `dyn futures::Future<Output = ()> + std::marker::Send` help: consider restricting type parameter `T` | 1522 | impl<T: std::marker::Sync> Generic<(T, T, T)> for Three { | +++++++++++++++++++
1 parent d71c74d commit 70bf4b0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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)