From 3bcb85ee658e7a5362f5e381c337f07381f916dc Mon Sep 17 00:00:00 2001 From: Josef Reinhard Brandl Date: Sat, 23 Jun 2018 13:32:53 +0200 Subject: `PinMut`: Add safe `get_mut` and rename unsafe fns to `get_mut_unchecked` and `map_unchecked` --- src/libstd/future.rs | 2 +- src/libstd/panic.rs | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 2da775fdc94..c1cc36f3b41 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -43,7 +43,7 @@ impl> !Unpin for GenFuture {} impl> Future for GenFuture { type Output = T::Return; fn poll(self: PinMut, cx: &mut task::Context) -> Poll { - set_task_cx(cx, || match unsafe { PinMut::get_mut(self).0.resume() } { + set_task_cx(cx, || match unsafe { PinMut::get_mut_unchecked(self).0.resume() } { GeneratorState::Yielded(()) => Poll::Pending, GeneratorState::Complete(x) => Poll::Ready(x), }) diff --git a/src/libstd/panic.rs b/src/libstd/panic.rs index 2c11c262488..451420ae88a 100644 --- a/src/libstd/panic.rs +++ b/src/libstd/panic.rs @@ -327,14 +327,9 @@ impl fmt::Debug for AssertUnwindSafe { impl<'a, F: Future> Future for AssertUnwindSafe { type Output = F::Output; - fn poll(mut self: PinMut, cx: &mut task::Context) -> Poll { - unsafe { - let pinned_field = PinMut::new_unchecked( - &mut PinMut::get_mut(self.reborrow()).0 - ); - - pinned_field.poll(cx) - } + fn poll(self: PinMut, cx: &mut task::Context) -> Poll { + let pinned_field = unsafe { PinMut::map_unchecked(self, |x| &mut x.0) }; + pinned_field.poll(cx) } } -- cgit 1.4.1-3-g733a5