rust-lang / rust-lang/rust

dead value causes `async` future to not be `Send`

Open
#144,391 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-await C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Here's the smallest example I could come up with, extracted from the larger project I was working on:

use std::future::Future;
use std::sync::RwLock;

pub async fn f(lock: RwLock<()>) {
    let guard = lock.read().unwrap();
    let () = *guard;
    drop(guard);
    wait().await;
}

pub async fn g(lock: RwLock<()>) {
    {
        let guard = lock.read().unwrap();
        let () = *guard;
    }
    wait().await;
}

pub async fn wait() {}

pub fn require_send(_fut: impl Future + Send) {}

pub fn check() {
    require_send(f(RwLock::new(())));
    require_send(g(RwLock::new(())));
}

I expected to see this happen: Both f and g should be equivalent, I think. The only difference between them is whether guard becomes dead at the end of a block or at the call to drop. In both cases, I believe it should be dead before the await.

Instead, this happened: g compiles without error, but attempting to use f reports "error: future cannot be sent between threads safely", because "future is not Send as [guard] is used across an await".

Meta

rustc --version --verbose:

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Using the Rust playground, I've also checked 1.89.0-beta.6 (2025-07-21 20c571f4ca4689572df8) and 1.90.0-nightly (2025-07-23 ace633090349fc5075b5).

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 reproduction from the issue with the reported Rust versions and compare the diagnostics for f and g. Trace the compiler's async-future lowering and liveness handling for the dead guard; done means both futures satisfy the Send bound without regressing the existing behavior.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.