use std::future::Future;
pub trait Acceptor<'a> {
fn accept(self) -> impl Future<Output = Self> + Send + 'a;
}
pub trait Stream {
fn consume<A>(self, acceptor: A) -> impl Future<Output = ()>
where
for<'a> A: Acceptor<'a>;
}
fn block_on<F: Send>(_: F) {}
fn check() {
block_on(async move {
struct S;
impl Stream for S {
async fn consume<A>(self, acceptor: A)
where
for<'a> A: Acceptor<'a>,
{
acceptor.accept().await;
}
}
struct A;
impl<'a> Acceptor<'a> for A {
fn accept(self) -> impl Future<Output = Self> + Send + 'a {
async { A }
}
}
S.consume(A).await;
});
}
godbolt
error: unable to satisfy constraints involving placeholders due to unknown implied bounds
error[E0277]: `{coroutine witness@<source>:25:13: 27:14}` cannot be sent between threads safely
--> <source>:19:5
|
19 | block_on(async move {
| ^ ---------- within this `{async block@<source>:19:14: 19:24}`
| _____|
| |
20 | | struct S;
21 | | impl Stream for S {
22 | | async fn consume<A>(self, acceptor: A)
... |
37 | | S.consume(A).await;
38 | | });
| |______^ `{coroutine witness@<source>:25:13: 27:14}` cannot be sent between threads safely
|
= help: within `{async block@<source>:19:14: 19:24}`, the trait `Send` is not implemented for `{coroutine witness@<source>:25:13: 27:14}`
note: required because it's used within this `async` fn body
--> <source>:25:13
|
25 | / {
26 | | acceptor.accept().await;
27 | | }
| |_____________^
note: required because it's used within this `async` block
--> <source>:19:14
|
19 | block_on(async move {
| ^^^^^^^^^^
note: required by a bound in `block_on`
--> <source>:16:16
|
16 | fn block_on<F: Send>(_: F) {}
| ^^^^ required by this bound in `block_on`
godbolt