- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-async-closures`async || {}``async || {}`C-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.
Description
I tried this code:
use std::future::Future;
pub trait Run<Ctx> {
    fn run(self, ctx: &mut Ctx) -> impl Future;
}
impl<Ctx, F, A> Run<Ctx> for (F, A)
where
    F: AsyncFnOnce(&mut Ctx, A),
    Self: Sized,
{
    fn run(self, ctx: &mut Ctx) -> impl Future {
        let (f, a) = self;
        (f)(ctx, a)
    }
}And got error
   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `F: AsyncFnOnce(F, A)` is not satisfied
  --> src/lib.rs:14:9
   |
14 |         (f)(ctx, a)
   |         ^^^^^^^^^^^ the trait `AsyncFnOnce(F, A)` is not implemented for `F`
error[E0308]: mismatched types
  --> src/lib.rs:14:13
   |
7  | impl<Ctx, F, A> Run<Ctx> for (F, A)
   |           - expected this type parameter
...
14 |         (f)(ctx, a)
   |         --- ^^^ expected type parameter `F`, found `&mut Ctx`
   |         |
   |         arguments to this function are incorrect
   |
   = note: expected type parameter `F`
           found mutable reference `&mut Ctx`
note: method defined here
  --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/async_function.rs:60:27
   |
60 |     extern "rust-call" fn async_call_once(self, args: Args) -> Self::CallOnceFuture;
   |                           ^^^^^^^^^^^^^^^
error[E0277]: the trait bound `F: AsyncFnOnce(F, A)` is not satisfied
  --> src/lib.rs:12:36
   |
12 |     fn run(self, ctx: &mut Ctx) -> impl Future {
   |                                    ^^^^^^^^^^^ the trait `AsyncFnOnce(F, A)` is not implemented for `F`
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 3 previous errors
While removing Self: Sized bound solves the problem:
  use std::future::Future;
  
  pub trait Run<Ctx> {
      fn run(self, ctx: &mut Ctx) -> impl Future;
  }
  
  impl<Ctx, F, A> Run<Ctx> for (F, A)
  where
      F: AsyncFnOnce(&mut Ctx, A),
-      Self: Sized,
  {
      fn run(self, ctx: &mut Ctx) -> impl Future {
          let (f, a) = self;
          (f)(ctx, a)
      }
  }Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-async-closures`async || {}``async || {}`C-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.