rust-lang / rust-lang/rust

`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

Open
#140,403 2 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-closures C-bug T-compiler T-types
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.