diff options
author | Taiki Endo <te316e89@gmail.com> | 2020-04-22 02:34:55 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-22 02:34:55 +0900 |
commit | 7e88b56be5fd70f53af6639c04546cf034a66d9e (patch) | |
tree | 10b73930c57e8bc1f938e14272de53a0833fdae2 /tokio-test | |
parent | 43bbbf61a2a87a879834ec644fd4f1c598e77640 (diff) |
test: remove unnecessary unsafe code (#2424)
Diffstat (limited to 'tokio-test')
-rw-r--r-- | tokio-test/src/task.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/tokio-test/src/task.rs b/tokio-test/src/task.rs index b31850ba..82d29134 100644 --- a/tokio-test/src/task.rs +++ b/tokio-test/src/task.rs @@ -119,20 +119,16 @@ impl<T: Stream> Spawn<T> { impl<T: Future> Future for Spawn<T> { type Output = T::Output; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { - // 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::Output> { + self.future.as_mut().poll(cx) } } impl<T: Stream> Stream for Spawn<T> { type Item = T::Item; - fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { - // 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<Option<Self::Item>> { + self.future.as_mut().poll_next(cx) } } |