diff options
| author | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-06-23 13:32:53 +0200 |
|---|---|---|
| committer | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-06-23 18:29:56 +0200 |
| commit | 3bcb85ee658e7a5362f5e381c337f07381f916dc (patch) | |
| tree | 2b081a664a10700167ee929b579ec2fa6700ef6e /src/libstd | |
| parent | 56e8f29dbe89f2109cacc8eb5e92ea3de32eefb9 (diff) | |
| download | rust-3bcb85ee658e7a5362f5e381c337f07381f916dc.tar.gz rust-3bcb85ee658e7a5362f5e381c337f07381f916dc.zip | |
`PinMut`: Add safe `get_mut` and rename unsafe fns to `get_mut_unchecked` and `map_unchecked`
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/future.rs | 2 | ||||
| -rw-r--r-- | src/libstd/panic.rs | 11 |
2 files changed, 4 insertions, 9 deletions
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<T: Generator<Yield = ()>> !Unpin for GenFuture<T> {} impl<T: Generator<Yield = ()>> Future for GenFuture<T> { type Output = T::Return; fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { - 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<T: fmt::Debug> fmt::Debug for AssertUnwindSafe<T> { impl<'a, F: Future> Future for AssertUnwindSafe<F> { type Output = F::Output; - fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { - unsafe { - let pinned_field = PinMut::new_unchecked( - &mut PinMut::get_mut(self.reborrow()).0 - ); - - pinned_field.poll(cx) - } + fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { + let pinned_field = unsafe { PinMut::map_unchecked(self, |x| &mut x.0) }; + pinned_field.poll(cx) } } |
