diff --git a/tokio-test/src/task.rs b/tokio-test/src/task.rs index b31850baf..82d29134c 100644 --- a/tokio-test/src/task.rs +++ b/tokio-test/src/task.rs @@ -119,20 +119,16 @@ impl Spawn { impl Future for Spawn { type Output = T::Output; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - // Safety: we only expose &mut T if T: Unpin therefore this is safe. - let future = unsafe { self.map_unchecked_mut(|s| &mut s.future) }; - future.poll(cx) + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + self.future.as_mut().poll(cx) } } impl Stream for Spawn { type Item = T::Item; - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - // Safety: we only expose &mut T if T: Unpin therefore this is safe. - let stream = unsafe { self.map_unchecked_mut(|s| &mut s.future) }; - stream.poll_next(cx) + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.future.as_mut().poll_next(cx) } }