rust-lang / rust-lang/rust

Send bound on RPITIT async method causes spurious lifetime errors

Open
#149,407 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-await C-bug fixed-by-higher-ranked-assumptions T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code (minimized from a larger case):

struct B;
struct C;

fn u(_c: &C, _b: &B) {}

trait T {
    fn a(&self, b: &B) -> impl Future<Output=()> + Send;
}

struct Timpl;

impl Timpl {
    async fn b<F>(&self, mut f: F)
    where
        F: AsyncFnMut(&mut C)
    {
        let mut c = C;
        f(&mut c).await;
        f(&mut c).await;
    }
}

impl T for Timpl {
    async fn a(&self, b: &B) {
        self.b(async |c| u(c, b)).await;
    }
}

I expect it to compile, instead an extremely vague 'lifetime error' is thrown out of rustc:

error[E0477]: the type `{async closure@src/lib.rs:25:16: 25:25}` does not fulfill the required lifetime
  --> src/lib.rs:24:5
   |
24 |     async fn a(&self, b: &B) {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0477`.

Removing the Send bound on T::a allows it to compile fine.

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (1be6b13be 2025-11-26)
binary: rustc
commit-hash: 1be6b13be73dc12e98e51b403add4c41a0b77759
commit-date: 2025-11-26
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

playground link

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

Reproduce the minimized example in src/lib.rs using the linked playground or the reported nightly rustc, then compare behavior with and without the Send bound on T::a. Read the E0477 explanation and compiler behavior for this async case; done means the example compiles as expected or produces a precise, non-spurious diagnostic.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.