-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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