async fn can't handle multiple lifetimes in a slice of slices · Issue #76547 · rust-lang/rust (original) (raw)

I tried this code:

use futures::{ Future, task::{Context, Poll} }; use std::pin::Pin;

pub struct ListFut<'a>(&'a mut [&'a mut [u8]]);

impl<'a> Future for ListFut<'a> { type Output = ();

fn poll(self: Pin<&mut Self>, _cx: &mut Context) -> Poll<Self::Output> {
    unimplemented!()
}

}

/// The compiler complains that "this parameter and the return type are declared /// with different lifetimes" pub async fn readv_at(bufs: &mut [&mut [u8]]) { ListFut(bufs).await }

/// The same thing, but making the lifetimes explicit pub async fn readv_at2<'a, 'b>(bufs: &'a mut [&'b mut [u8]]) { ListFut(bufs).await }

/// But the compiler accepts this method just fine, because there is only one /// lifetime. pub async fn readv_at1<'a>(bufs: &'a mut [&'a mut [u8]]) { ListFut(bufs).await }

/// Even if we explicitly bound one lifetime by the other, the compiler still /// can't handle it. pub async fn readv_at3<'a, 'b: 'a>(bufs: &'a mut [&'b mut [u8]]) { ListFut(bufs).await }

I expected to see this happen: No error

Instead, this happened: For every variant with two lifetimes, the compiler complains "these two types are declared with different lifetimes... but data from bufs flows into bufs here"

This looks similar to #56238 , but I see that the commit which closed that issue didn't included any test cases involving slices.

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (d006f5734 2020-08-28)
rustc 1.42.0 (b8cedc004 2020-03-09)