Defaulted method with `self: Arc<Self>` doesn't work
ChayimFriedman2 opened this issue · comments
Chayim Refael Friedman commented
Arc
generates a where Self: Send
bound, but for Arc
it is not enough - it requires also T: Sync
to be Send
. This make the following code failing to compile:
#[async_trait]
trait Trait {
async fn foo(self: Arc<Self>) {}
}
error: future cannot be sent between threads safely
--> src/lib.rs:7:35
|
7 | async fn foo(self: Arc<Self>) {}
| ^^ future created by async block is not `Send`
|
note: captured value is not `Send`
--> src/lib.rs:7:18
|
7 | async fn foo(self: Arc<Self>) {}
| ^^^^ has type `Arc<Self>` which is not `Send`
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
Adding Sync
as a supertrait works, but ideally the macro should also add a Self: Sync
bound (even though I don't know how it can identify Arc
being used), or at least document that.