Skip to content

higher-ranked-assumptions: "unable to satisfy constraints involving placeholders" when proving Send for AFIT/RPITIT future constrained by HRTB #157339

@tmandry

Description

@tmandry
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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-bugCategory: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions