diff --git a/src/lib.rs b/src/lib.rs index eccd1ce..ac97ceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![doc = include_str!("../README.md")] #![forbid(rust_2018_idioms)] -#![deny(missing_docs, unsafe_code)] +#![forbid(missing_docs, unsafe_code)] #![warn(clippy::all, clippy::pedantic)] use std::{convert::TryFrom, sync::Arc}; @@ -33,7 +33,7 @@ mod private { use x509_cert::{der::Decode, TbsCertificate}; pub struct TlsConnectFuture { - pub inner: tokio_rustls::Connect, + inner: tokio_rustls::Connect, } impl Future for TlsConnectFuture @@ -42,11 +42,8 @@ mod private { { type Output = io::Result>; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - // SAFETY: If `self` is pinned, so is `inner`. - #[allow(unsafe_code)] - let fut = unsafe { self.map_unchecked_mut(|this| &mut this.inner) }; - fut.poll(cx).map_ok(RustlsStream) + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + Pin::new(&mut self.inner).poll(cx).map_ok(RustlsStream) } } @@ -74,16 +71,6 @@ mod private { pub struct RustlsStream(TlsStream); - impl RustlsStream { - pub fn project_stream(self: Pin<&mut Self>) -> Pin<&mut TlsStream> { - // SAFETY: When `Self` is pinned, so is the inner `TlsStream`. - #[allow(unsafe_code)] - unsafe { - self.map_unchecked_mut(|this| &mut this.0) - } - } - } - impl tokio_postgres::tls::TlsStream for RustlsStream where S: AsyncRead + AsyncWrite + Unpin, @@ -126,11 +113,11 @@ mod private { S: AsyncRead + AsyncWrite + Unpin, { fn poll_read( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - self.project_stream().poll_read(cx, buf) + Pin::new(&mut self.0).poll_read(cx, buf) } } @@ -139,22 +126,25 @@ mod private { S: AsyncRead + AsyncWrite + Unpin, { fn poll_write( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - self.project_stream().poll_write(cx, buf) + Pin::new(&mut self.0).poll_write(cx, buf) } - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - self.project_stream().poll_flush(cx) + fn poll_flush( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll> { + Pin::new(&mut self.0).poll_flush(cx) } fn poll_shutdown( - self: Pin<&mut Self>, + mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll> { - self.project_stream().poll_shutdown(cx) + Pin::new(&mut self.0).poll_shutdown(cx) } } }