rust-lang / rust-lang/rust

Misleading `lifetime bound not satisfied` with superfluous lifetime parameter

Open
#143,971 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
trait MyTrait {
    fn trait_fn<'a>(x: &mut i32) -> impl Future<Output = ()> + use<'a, Self> + Send;
}

fn using_fn<T: MyTrait>() -> impl Future<Output = ()> + Send + 'static {
    async move {
        let mut observer: i32 = 0;
        T::trait_fn(&mut observer).await
    }
}
Current output
error: lifetime bound not satisfied
   --> src/raft/mod.rs:992:5
    |
992 | /     async move {
993 | |         let mut observer: i32=0;
994 | |         T::trait_fn(
995 | |             &mut observer,
996 | |         ).await
997 | |     }
    | |_____^
    |
    = note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
Desired output
Superfluous lifetime parameter `'a`
Rationale and extra context

I ran into the lifetime bound not satisfied error mentioned in #100013 and managed to reduce it to this. The discussion on this and related issues led me to believe that the problem is caused by a missing Send implementation for one of the many types I used in the future, but that seems to not be the case. In reducing the code to this, I finally noticed that I forgot the 'a lifetime on the x parameter in trait_fn. It should have been x: &'a mut i32. I don't think introducing a lifetime parameter and only using it in the use<> bound would ever be desired, though I might be wrong about that.

Debugging this was very frustrating as none of the workarounds from #100013 and related issues worked. I tried both the always-send and send-future crates. As the error is reported by the compiler on an async function which indirectly calls this one (and not on the offending function), this was hard to narrow down.

Other cases

Rust Version
rustc 1.90.0-nightly (a00149764 2025-07-14)
binary: rustc
commit-hash: a001497644bc229f1abcc5b2528733386591647f
commit-date: 2025-07-14
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8
Anything else?

No response

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 reproducing the minimized Rust example with the reported nightly compiler and compare the current diagnostic with the desired message. Trace how the compiler reports the async block's lifetime error and the unused 'a parameter in trait_fn; done means the reduced case reports the superfluous lifetime clearly without regressing related lifetime diagnostics.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.