Open
Description
async move
closures do not implement FnMut
(and therefore also not Fn
) when capturing a copyable value, but closures returning a async move
block do.
I tried this code:
fn main() {}
fn needs_fn_mut<T, F: FnMut() -> T>(mut f: F) -> T {
(f)()
}
fn hello() -> impl Future<Output = u32> {
let copyable = 0;
needs_fn_mut(async move || { copyable })
}
Same with Fn
fn main() {}
fn needs_fn<T, F: Fn() -> T>(f: F) -> T {
(f)()
}
fn hello() -> impl Future<Output = u32> {
let copyable = 0;
needs_fn(async move || { copyable })
}
Working code with async move
blocks:
fn main() {}
fn needs_fn_mut<T, F: FnMut() -> T>(mut f: F) -> T {
(f)()
}
fn hello() -> impl Future<Output = u32> {
let copyable = 0;
needs_fn_mut(|| async move { copyable })
}
Same with Fn
fn main() {}
fn needs_fn<T, F: Fn() -> T>(f: F) -> T {
(f)()
}
fn hello() -> impl Future<Output = u32> {
let copyable = 0;
needs_fn(|| async move { copyable })
}
Meta
rustc --version --verbose
:
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
Backtrace
error: async closure does not implement `FnMut` because it captures state from its environment
--> <anon>:10:18
|
10 | needs_fn_mut(async move || { copyable })
| ------------ ^^^^^^^^^^^^^
| |
| required by a bound introduced by this call
|
note: required by a bound in `needs_fn_mut`
--> <anon>:3:23
|
3 | fn needs_fn_mut<T, F: FnMut() -> T>(mut f: F) -> T {
| ^^^^^^^^^^^^ required by this bound in `needs_fn_mut`
error: aborting due to 1 previous error
This issue may be linked to #125247.