Open
Description
I tried this code:
#![feature(impl_trait_in_fn_trait_return)]
#![feature(impl_trait_in_assoc_type)]
use std::future::Future;
trait Kind {
type Func<I, R>;
fn stub<I, R>() -> Self::Func<I, R>;
}
struct A;
impl Kind for A {
type Func<I, R> = Box<dyn Fn(I) -> impl Future<Output = R>>;
fn stub<I, R>() -> Self::Func<I, R> {
Box::new(|_| async { unimplemented!() })
}
}
struct Owner<K: Kind> {
k: K,
}
impl<K: Kind> Owner<K> {
fn run<I, R>(&self, _func: K::Func<I, R>) {
// do stuff with func
}
}
fn main() {
let o = Owner { k: A };
o.run(Box::new(|_| async {
// Do stuff
}));
}
This almost compiles. If you remove the o.run
call it otherwise compiles. It seems that rust isn't able to determine that the async block impls the Future trait in main (but does work in the stub!). Think it's related to #106527. cc @compiler-errors
error[E0308]: mismatched types
--> src/main.rs:34:24
|
15 | type Func<I, R> = Box<dyn Fn(I) -> impl Future<Output = R>>;
| ----------------------- the expected future
...
34 | o.run(Box::new(|_| async {
| ________________________^
35 | | // Do stuff
36 | | }));
| |_____^ expected future, found `async` block
|
= note: expected opaque type `<A as Kind>::Func<_, _>::{opaque#0}`
found `async` block `{async block@src/main.rs:34:24: 36:6}`
Meta
rustc --version --verbose
:
rustc 1.78.0-nightly (3b1717c05 2024-03-10)
binary: rustc
commit-hash: 3b1717c052de4a2dbdd3badb0e7a885f40a8ad9e
commit-date: 2024-03-10
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0