diff options
| author | bors <bors@rust-lang.org> | 2018-05-24 20:58:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-24 20:58:12 +0000 |
| commit | c2d46037fa6617408155dcba6251d7c4e123b4f5 (patch) | |
| tree | 6e77f0ba80651beec17a80dfe7ca33923056e949 /src | |
| parent | 07465222ca9454d7c274908424a5e084710efd7e (diff) | |
| parent | 15d2f965d83672dc8e7edc972ab256e587878332 (diff) | |
| download | rust-c2d46037fa6617408155dcba6251d7c4e123b4f5.tar.gz rust-c2d46037fa6617408155dcba6251d7c4e123b4f5.zip | |
Auto merge of #50984 - cramertj:unpin-changes, r=aturon
Unpin changes r? @aturon cc @withoutboats, @RalfJung, @pythonesque, #49150
Diffstat (limited to 'src')
| -rw-r--r-- | src/liballoc/boxed.rs | 2 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/marker.rs | 12 | ||||
| -rw-r--r-- | src/libcore/mem.rs | 10 | ||||
| -rw-r--r-- | src/libcore/option.rs | 10 |
5 files changed, 32 insertions, 3 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index a1567344235..a83ce7f379f 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -850,4 +850,4 @@ impl<T: ?Sized> fmt::Pointer for PinBox<T> { impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {} #[unstable(feature = "pin", issue = "49150")] -unsafe impl<T: ?Sized> Unpin for PinBox<T> {} +impl<T: ?Sized> Unpin for PinBox<T> {} diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index d37629ced11..2121bc44380 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -74,6 +74,7 @@ #![deny(missing_debug_implementations)] #![feature(allow_internal_unstable)] +#![feature(arbitrary_self_types)] #![feature(asm)] #![feature(associated_type_defaults)] #![feature(attr_literals)] diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 6c8ee0eda11..77db165bcbd 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -605,7 +605,17 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {} /// /// [`PinMut`]: ../mem/struct.PinMut.html #[unstable(feature = "pin", issue = "49150")] -pub unsafe auto trait Unpin {} +pub auto trait Unpin {} + +/// A type which does not implement `Unpin`. +/// +/// If a type contains a `Pinned`, it will not implement `Unpin` by default. +#[unstable(feature = "pin", issue = "49150")] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +pub struct Pinned; + +#[unstable(feature = "pin", issue = "49150")] +impl !Unpin for Pinned {} /// Implementations of `Copy` for primitive types. /// diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 20445def634..059c099d66b 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -1164,6 +1164,14 @@ impl<'a, T: ?Sized> PinMut<'a, T> { { PinMut { inner: f(this.inner) } } + + /// Assign a new value to the memory behind the pinned reference. + #[unstable(feature = "pin", issue = "49150")] + pub fn set(this: PinMut<'a, T>, value: T) + where T: Sized, + { + *this.inner = value; + } } #[unstable(feature = "pin", issue = "49150")] @@ -1207,4 +1215,4 @@ impl<'a, T: ?Sized> fmt::Pointer for PinMut<'a, T> { impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinMut<'a, U>> for PinMut<'a, T> {} #[unstable(feature = "pin", issue = "49150")] -unsafe impl<'a, T: ?Sized> Unpin for PinMut<'a, T> {} +impl<'a, T: ?Sized> Unpin for PinMut<'a, T> {} diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 28f37f72d6f..1e615042a6d 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -147,6 +147,7 @@ use iter::{FromIterator, FusedIterator, TrustedLen}; use {mem, ops}; +use mem::PinMut; // Note that this is not a lang item per se, but it has a hidden dependency on // `Iterator`, which is one. The compiler assumes that the `next` method of @@ -269,6 +270,15 @@ impl<T> Option<T> { } } + /// Converts from `Option<T>` to `Option<PinMut<'_, T>>` + #[inline] + #[unstable(feature = "pin", issue = "49150")] + pub fn as_pin_mut<'a>(self: PinMut<'a, Self>) -> Option<PinMut<'a, T>> { + unsafe { + PinMut::get_mut(self).as_mut().map(|x| PinMut::new_unchecked(x)) + } + } + ///////////////////////////////////////////////////////////////////////// // Getting to contained values ///////////////////////////////////////////////////////////////////////// |
