Lifetime trouble on Future with an output type that requires a lifetime


I'm trying to implement an async DataLock (mutex like) machanism using Futures. However, I've trouble implementing the Future with the required lifetime paramater on the output type.

This is what I got so far:

impl<'a, T: 'static> Future for AsyncDataLockFuture<'a, T> {
    type Output = TryDataLock<'a, T>;

    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        let this = self.get_mut(); // <-- here I got an error, see below

I stripped a way some code but the issue is this:

cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
expected  `core::pin::Pin<&mut asyncdatalock::AsyncDataLockFuture<'a, T>>`
   found  `core::pin::Pin<&mut asyncdatalock::AsyncDataLockFuture<'a, T>>`
expected  `core::future::Future`
   found  `core::future::Future`rustc(E0495), 5): first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 119:5..., 25): that the types are compatible, 6): but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 116:6..., 79): that the types are compatible

Well even if the actual and expected types in the message looks quite the same to me the issue seem to be the anonymous lifetime in the cx: &mut Context<'_> part. But when handing here the 'a lifetime the compiler complains that the signatures of the poll functions does not match between trait definition and implementation.

So any hint would be highly appreciated :smiley:
Thanks in advance.

This is the same problem as they ran into here.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.