`async closure does not implement ``FnMut`` because it captures state from its environment` for `async move` closures capturing copyable values, while closures returning `async move` blocks work fine
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the minimal reproducer with rustc and compare the async move closure examples with the closures returning async move blocks. Read the behavior around the Fn and FnMut bounds shown in the reproducer, and use the linked issue #125247 for context. Done means copyable captures in async move closures behave consistently with the working block form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100