diff options
Diffstat (limited to 'src/io/util/fill_buf.rs')
-rw-r--r-- | src/io/util/fill_buf.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/io/util/fill_buf.rs b/src/io/util/fill_buf.rs index 98ae2ea..3655c01 100644 --- a/src/io/util/fill_buf.rs +++ b/src/io/util/fill_buf.rs @@ -34,15 +34,16 @@ impl<'a, R: AsyncBufRead + ?Sized + Unpin> Future for FillBuf<'a, R> { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { let me = self.project(); - // Due to a limitation in the borrow-checker, we cannot return the value - // directly on Ready. Once Rust starts using the polonius borrow checker, - // this can be simplified. let reader = me.reader.take().expect("Polled after completion."); match Pin::new(&mut *reader).poll_fill_buf(cx) { - Poll::Ready(_) => match Pin::new(reader).poll_fill_buf(cx) { - Poll::Ready(slice) => Poll::Ready(slice), - Poll::Pending => panic!("poll_fill_buf returned Pending while having data"), + Poll::Ready(Ok(slice)) => unsafe { + // Safety: This is necessary only due to a limitation in the + // borrow checker. Once Rust starts using the polonius borrow + // checker, this can be simplified. + let slice = std::mem::transmute::<&[u8], &'a [u8]>(slice); + Poll::Ready(Ok(slice)) }, + Poll::Ready(Err(err)) => Poll::Ready(Err(err)), Poll::Pending => { *me.reader = Some(reader); Poll::Pending |