-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
I tried this code:
type BoxedWork = Box<dyn Fn(u32) -> u32>;
// error[E0308]: mismatched types
fn make_work_builder() -> impl AsyncFn() -> BoxedWork {
async || Box::new(move |x| x + 1)
}
// With a regular `Fn` all is fine.
fn make_sync_work_builder() -> impl Fn() -> BoxedWork {
|| Box::new(|x| x + 1)
}
// Wrapping the Box into a struct fixes it. WTF.
struct WrappedWork { work: BoxedWork }
fn make_wrapped_work_builder() -> impl AsyncFn() -> WrappedWork {
async || WrappedWork { work: Box::new(|x| x + 1) }
}
I expected to see this happen: It compiles.
Instead, this happened: The first function make_work_builder
fails to compile with
error[E0308]: mismatched types
--> src/lib.rs:5:14
|
5 | async || Box::new(move |x| x + 1)
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `dyn Fn`, found closure
|
= note: expected `async` closure body `{async closure body@src/lib.rs:5:14: 5:38}` (`dyn Fn`)
found `async` closure body `{async closure body@src/lib.rs:5:14: 5:38}` (closure)
= note: no two async blocks, even if identical, have the same type
= help: consider pinning your async block and casting it to a trait object
This seems wrong, especially considering that the latter two examples compile just fine.
Meta
Reproduces on playground with current stable 1.89 but also in my local project with 1.88
rustc --version --verbose
:
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: aarch64-apple-darwin
release: 1.88.0
LLVM version: 20.1.5
oatmealdealer
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.