diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-06-26 11:35:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-26 11:35:37 +0200 |
| commit | b71f6df5dd74804682a500ca7eb251e34e58b1cb (patch) | |
| tree | b7f5b03a6c2ec0f17c8500aaa7aa42a7f9327e13 /src/libstd | |
| parent | 1215965a12f94b0e304b41ebf71d17f988f42f96 (diff) | |
| parent | 3bcb85ee658e7a5362f5e381c337f07381f916dc (diff) | |
| download | rust-b71f6df5dd74804682a500ca7eb251e34e58b1cb.tar.gz rust-b71f6df5dd74804682a500ca7eb251e34e58b1cb.zip | |
Rollup merge of #51730 - MajorBreakfast:pin-get-mut-unchecked, r=withoutboats
New safe associated functions for PinMut - Add safe `get_mut` and `map` - Rename unsafe equivalents to `get_mut_unchecked` and `map_unchecked` The discussion about this starts [in this comment](https://github.com/rust-lang/rust/issues/49150#issuecomment-399604573) on the tracking issue.
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) } } |
