Open
Description
I tried this code:
use std::{
future::Future,
marker::PhantomData,
{pin::Pin, sync::Arc},
};
fn validate_signature() -> impl Future<Output = ()> + Send {
let certificate_store = Cache::<CertificateRetriever>::new();
let res = Box::pin(async move {
certificate_store.get().await;
});
fn foo<T: 'static>(_c: &T) {}
res
}
type CertificateRetriever =
Arc<dyn Retrieve<Future = Pin<Box<dyn Future<Output = ()> + Send + 'static>>>>;
trait Retrieve: Send + Sync {
type Future: Future<Output = ()> + Send + 'static;
fn get(&self) -> Self::Future;
}
impl<R: Retrieve + ?Sized> Retrieve for Arc<R> {
type Future = R::Future;
fn get(&self) -> Self::Future {
todo!()
}
}
struct Cache<R: Retrieve> {
marker: PhantomData<R>,
}
impl<R> Cache<R>
where
R: Retrieve + 'static,
{
fn new() -> Self {
todo!()
}
async fn get(&self) {
self.get_value().await
}
fn get_value(&self) -> R::Future {
todo!()
}
}
I expected to see this to compile fine, minor changes to the code cause it to compile.
Instead, I get this error:
error[E0477]: the type `Pin<Box<dyn Future<Output = ()> + Send>>` does not fulfill the required lifetime
--> src/lib.rs:7:28
|
7 | fn validate_signature() -> impl Future<Output = ()> + Send {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: type must satisfy the static lifetime
error: aborting due to previous error
This may be a duplicate of #80052 but as it involves no associated constants I'm keeping it separate for now.
Compiled with rustc 1.52.1