Closed
Description
I tried this code:
#![feature(async_closure)]
use std::future::Future;
fn main() {
let example = async move || {
};
test(example);
}
fn test<T: Future<Output = ()>, F: Fn() -> T>(given: F) {}
I expected to see this happen: example is of type F, the behavior of Rust prior to adding coroutines
Instead, this happened:
error[E0277]: expected a `Fn()` closure, found `{coroutine-closure@src\main.rs:6:19: 6:32}`
--> src\main.rs:9:10
|
9 | test(example);
| ---- ^^^^^^^ expected an `Fn()` closure, found `{coroutine-closure@src\main.rs:6:19: 6:32}`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn<()>` is not implemented for `{coroutine-closure@src\main.rs:6:19: 6:32}`
= note: wrap the `{coroutine-closure@src\main.rs:6:19: 6:32}` in a closure with no arguments: `|| { /* code */ }`
Meta
binary: rustc
commit-hash: d44e3b95cb9d410d89cb8ab3233906a33f43756a
commit-date: 2024-02-09
host: x86_64-pc-windows-msvc
release: 1.78.0-nightly
LLVM version: 17.0.6
This error started happening with the addition of coroutines, the code works on older nightly versions (don't know exactly when it started). My guess is Rust incorrectly converts all async closures into coroutines.