Closed as not planned
Closed as not planned
Description
I tried this code:
#![feature(async_closure)]
use std::future::Future;
fn main() {
let variable = 12;
let reference = &variable;
let example = async move || {
println!("{}", reference);
};
test(example);
}
fn test<T: Future<Output = ()>, F: Fn() -> T>(given: F) {
}
I expected to see this happen: No compiler errors
Instead, this happened:
error[E0277]: expected a `Fn()` closure, found `{async closure@src\main.rs:8:19: 8:32}`
--> src\main.rs:11:10
|
11 | test(example);
| ---- ^^^^^^^ expected an `Fn()` closure, found `{async closure@src\main.rs:8:19: 8:32}`
| |
| required by a bound introduced by this call
|
= help: the trait `Fn<()>` is not implemented for `{async closure@src\main.rs:8:19: 8:32}`
= note: wrap the `{async closure@src\main.rs:8:19: 8:32}` in a closure with no arguments: `|| { /* code */ }`
= note: `{async closure@src\main.rs:8:19: 8:32}` implements `FnOnce`, but it must implement `Fn`, which is more general
Meta
rustc --version --verbose
:
rustc 1.78.0-nightly (1a648b397 2024-02-11)
binary: rustc
commit-hash: 1a648b397dedc98ada3dd3360f6d661ec2436c56
commit-date: 2024-02-11
host: x86_64-pc-windows-msvc
release: 1.78.0-nightly
LLVM version: 17.0.6
This bug was introduced between nightly-2024-02-06 (where the code builds correctly) and nightly-2024-02-27 (where the error happens), and is still present on nightly-2024-02-11 (the latest when this was released). This bug is likely related to #120886, which was fixed by #120712.