- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & awaitregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
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
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & awaitregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.