rust-lang / rust-lang/rust

[async closure] implementation of `Send` is not general enough using tokio channel

Open
#139,475 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-closures A-auto-traits A-concurrency C-bug fixed-by-higher-ranked-assumptions
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

use tokio::sync::mpsc;

pub async fn main() {
    tokio::spawn(async move { run().await });
}

pub async fn run() {
    let (tx, _rx) = mpsc::channel(12);
    let f = async || {
        tx.send(()).await;
    };
    f().await; // ok
    run_async_closure(f).await; // error
}

pub async fn run_async_closure(mut f: impl AsyncFnMut()) {
    f().await;
}

I expected to see this happen: no error as this is a very normal use case of async closure.

Instead, this happened: compiler complaining about the lifetime of the tokio mpsc::Sender.

Meta

rustc --version --verbose:

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: aarch64-apple-darwin
release: 1.86.0
LLVM version: 19.1.7
Backtrace

error: implementation of `Send` is not general enough
 --> src/lib.rs:4:5
  |
4 |     tokio::spawn(async move { run().await });
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Send` is not general enough
  |
  = note: `Send` would have to be implemented for the type `&'0 tokio::sync::mpsc::Sender<()>`, for any lifetime `'0`...
  = note: ...but `Send` is actually implemented for the type `&'1 tokio::sync::mpsc::Sender<()>`, for some specific lifetime `'1`

error: could not compile `test_async_closure` (lib) due to 1 previous error

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 with the reproducer in src/lib.rs and run it with the shown async closure, tokio mpsc channel, and tokio::spawn setup. Trace how the async closure is passed to run_async_closure and how the compiler reports the Send lifetime requirement. Done means the reproducer compiles without the “implementation of Send is not general enough” error.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.