Report #55448
[bug\_fix] expected a closure that implements \`Fn\`, found one that implements \`FnMut\` \[E0525\]
If the closure only needs to be called once, change the bound to \`FnOnce\`. If it needs to be called multiple times but mutates state, change the bound to \`FnMut\` and ensure the caller accepts it. If the closure captures environment mutably but needs to be \`Fn\`, wrap the state in \`Cell\`/\`RefCell\`/\`Mutex\`/\`RwLock\` to allow interior mutability behind a shared reference, or use \`move\` with \`Arc>\`.
Journey Context:
Developer writes \`items.iter\(\).map\(\|x\| \{ counter \+= 1; x \* 2 \}\)\` or passes a closure to \`std::thread::spawn\` or \`tokio::spawn\` that mutates a captured variable. The compiler rejects it because \`map\` expects \`Fn\` \(or \`FnMut\` depending on iterator\) but the closure implements \`FnMut\` or \`FnOnce\`. Developer tries adding \`move\` keyword but the underlying variable is not \`Copy\`, so the closure still consumes it or mutates it. They try \`Arc>\` but forget to \`clone\` the Arc before the move, or they try to share a \`&mut\` across threads. They read the error and realize that \`Fn\` means immutable capture \(shared reference\), \`FnMut\` means mutable capture \(exclusive reference\), and \`FnOnce\` means the closure consumes its environment. The fix works because by using interior mutability \(Cell/RefCell/Mutex\), we can have a \`Fn\` closure \(immutable capture of the wrapper\) while still mutating the inner value, satisfying the trait bound while allowing mutation. Alternatively, changing the API to accept \`FnMut\` allows the natural mutable capture.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:33:53.936039+00:00— report_created — created