mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
io: fix unsound pin projection in read_buf and write_buf (#2612)
This commit is contained in:
parent
1636910f0a
commit
1769f65d37
@ -221,7 +221,7 @@ cfg_io_util! {
|
||||
/// ```
|
||||
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Sized + Unpin,
|
||||
B: BufMut,
|
||||
{
|
||||
read_buf(self, buf)
|
||||
|
@ -180,7 +180,7 @@ cfg_io_util! {
|
||||
/// ```
|
||||
fn write_buf<'a, B>(&'a mut self, src: &'a mut B) -> WriteBuf<'a, Self, B>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: Sized + Unpin,
|
||||
B: Buf,
|
||||
{
|
||||
write_buf(self, src)
|
||||
|
@ -8,7 +8,7 @@ use std::task::{Context, Poll};
|
||||
|
||||
pub(crate) fn read_buf<'a, R, B>(reader: &'a mut R, buf: &'a mut B) -> ReadBuf<'a, R, B>
|
||||
where
|
||||
R: AsyncRead,
|
||||
R: AsyncRead + Unpin,
|
||||
B: BufMut,
|
||||
{
|
||||
ReadBuf { reader, buf }
|
||||
@ -26,16 +26,13 @@ cfg_io_util! {
|
||||
|
||||
impl<R, B> Future for ReadBuf<'_, R, B>
|
||||
where
|
||||
R: AsyncRead,
|
||||
R: AsyncRead + Unpin,
|
||||
B: BufMut,
|
||||
{
|
||||
type Output = io::Result<usize>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
||||
// safety: no data is moved from self
|
||||
unsafe {
|
||||
let me = self.get_unchecked_mut();
|
||||
Pin::new_unchecked(&mut *me.reader).poll_read_buf(cx, &mut me.buf)
|
||||
}
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
||||
let me = &mut *self;
|
||||
Pin::new(&mut *me.reader).poll_read_buf(cx, me.buf)
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ cfg_io_util! {
|
||||
/// asynchronous manner, returning a future.
|
||||
pub(crate) fn write_buf<'a, W, B>(writer: &'a mut W, buf: &'a mut B) -> WriteBuf<'a, W, B>
|
||||
where
|
||||
W: AsyncWrite,
|
||||
W: AsyncWrite + Unpin,
|
||||
B: Buf,
|
||||
{
|
||||
WriteBuf { writer, buf }
|
||||
@ -28,16 +28,13 @@ where
|
||||
|
||||
impl<W, B> Future for WriteBuf<'_, W, B>
|
||||
where
|
||||
W: AsyncWrite,
|
||||
W: AsyncWrite + Unpin,
|
||||
B: Buf,
|
||||
{
|
||||
type Output = io::Result<usize>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
||||
// safety: no data is moved from self
|
||||
unsafe {
|
||||
let me = self.get_unchecked_mut();
|
||||
Pin::new_unchecked(&mut *me.writer).poll_write_buf(cx, &mut me.buf)
|
||||
}
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
|
||||
let me = &mut *self;
|
||||
Pin::new(&mut *me.writer).poll_write_buf(cx, me.buf)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user