dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

Longhand method receivers emit the wrong bound #83

Closed dtolnay closed 4 years ago

dtolnay commented 4 years ago
use async_trait::async_trait;

#[async_trait]
pub trait Trait {
    async fn f(&self) {} // works
    async fn g(self: &Self) {} // does not work
}
error[E0277]: `Self` cannot be shared between threads safely
   --> tests/test.rs:564:33
    |
564 |         async fn g(self: &Self) {}
    |                                 ^^ `Self` cannot be shared between threads safely
    |
    = help: the trait `std::marker::Sync` is not implemented for `Self`
    = note: required because of the requirements on the impl of `std::marker::Send` for `&Self`
    = note: required because it appears within the type `[static generator@tests/test.rs:564:33: 564:35 _self:&Self {}]`
    = note: required because it appears within the type `std::future::from_generator::GenFuture<[static generator@tests/test.rs:564:33: 564:35 _self:&Self {}]>`
    = note: required because it appears within the type `impl std::future::Future`
    = note: required because it appears within the type `impl std::future::Future`
    = note: required for the cast to the object type `dyn std::future::Future<Output = ()> + std::marker::Send`