about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTaylor Cramer <cramertj@google.com>2018-12-17 17:19:32 -0800
committerTaylor Cramer <cramertj@google.com>2018-12-21 20:41:24 -0800
commit20d694a95f0110fe253bfca7e9929bfdc6440c7e (patch)
tree59c2a5427db23ce29134edfcc5228514340e3ac7
parentabaa9344d4c10a45d7725534145007a8284dabe8 (diff)
downloadrust-20d694a95f0110fe253bfca7e9929bfdc6440c7e.tar.gz
rust-20d694a95f0110fe253bfca7e9929bfdc6440c7e.zip
Update Pin API to match the one proposed for stabilization
Remove pin::Unpin reexport and add Unpin to the prelude.
Change Pin associated functions to methods.
Rename get_mut_unchecked_ to get_unchecked_mut
Remove impl Unpin for Pin
Mark Pin repr(transparent)
-rw-r--r--src/libcore/future/future.rs2
-rw-r--r--src/libcore/option.rs2
-rw-r--r--src/libcore/pin.rs33
-rw-r--r--src/libcore/prelude/v1.rs2
-rw-r--r--src/libstd/future.rs2
5 files changed, 18 insertions, 23 deletions
diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs
index 5dee1d6dd3a..da3aa8449ba 100644
--- a/src/libcore/future/future.rs
+++ b/src/libcore/future/future.rs
@@ -120,7 +120,7 @@ impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
 
 impl<P> Future for Pin<P>
 where
-    P: ops::DerefMut,
+    P: Unpin + ops::DerefMut,
     P::Target: Future,
 {
     type Output = <<P as ops::Deref>::Target as Future>::Output;
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 44d632ece05..0d7ddfc20b6 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -285,7 +285,7 @@ impl<T> Option<T> {
     #[unstable(feature = "pin", issue = "49150")]
     pub fn as_pin_mut<'a>(self: Pin<&'a mut Option<T>>) -> Option<Pin<&'a mut T>> {
         unsafe {
-            Pin::get_mut_unchecked(self).as_mut().map(|x| Pin::new_unchecked(x))
+            Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x))
         }
     }
 
diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs
index 521ce9b5f6b..0436a709b31 100644
--- a/src/libcore/pin.rs
+++ b/src/libcore/pin.rs
@@ -100,12 +100,9 @@
 #![unstable(feature = "pin", issue = "49150")]
 
 use fmt;
-use marker::Sized;
+use marker::{Sized, Unpin};
 use ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
 
-#[doc(inline)]
-pub use marker::Unpin;
-
 /// A pinned pointer.
 ///
 /// This is a wrapper around a kind of pointer which makes that pointer "pin" its
@@ -121,6 +118,7 @@ pub use marker::Unpin;
 // cannot move the value behind `pointer`.
 #[unstable(feature = "pin", issue = "49150")]
 #[fundamental]
+#[repr(transparent)]
 #[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
 pub struct Pin<P> {
     pointer: P,
@@ -200,10 +198,10 @@ impl<'a, T: ?Sized> Pin<&'a T> {
     /// because it is one of the fields of that value), and also that you do
     /// not move out of the argument you receive to the interior function.
     #[unstable(feature = "pin", issue = "49150")]
-    pub unsafe fn map_unchecked<U, F>(this: Pin<&'a T>, func: F) -> Pin<&'a U> where
+    pub unsafe fn map_unchecked<U, F>(self: Pin<&'a T>, func: F) -> Pin<&'a U> where
         F: FnOnce(&T) -> &U,
     {
-        let pointer = &*this.pointer;
+        let pointer = &*self.pointer;
         let new_pointer = func(pointer);
         Pin::new_unchecked(new_pointer)
     }
@@ -217,8 +215,8 @@ impl<'a, T: ?Sized> Pin<&'a T> {
     /// with the same lifetime as the original `Pin`.
     #[unstable(feature = "pin", issue = "49150")]
     #[inline(always)]
-    pub fn get_ref(this: Pin<&'a T>) -> &'a T {
-        this.pointer
+    pub fn get_ref(self: Pin<&'a T>) -> &'a T {
+        self.pointer
     }
 }
 
@@ -226,8 +224,8 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
     /// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
     #[unstable(feature = "pin", issue = "49150")]
     #[inline(always)]
-    pub fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> {
-        Pin { pointer: this.pointer }
+    pub fn into_ref(self: Pin<&'a mut T>) -> Pin<&'a T> {
+        Pin { pointer: self.pointer }
     }
 
     /// Get a mutable reference to the data inside of this `Pin`.
@@ -241,10 +239,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
     /// with the same lifetime as the original `Pin`.
     #[unstable(feature = "pin", issue = "49150")]
     #[inline(always)]
-    pub fn get_mut(this: Pin<&'a mut T>) -> &'a mut T
+    pub fn get_mut(self: Pin<&'a mut T>) -> &'a mut T
         where T: Unpin,
     {
-        this.pointer
+        self.pointer
     }
 
     /// Get a mutable reference to the data inside of this `Pin`.
@@ -259,8 +257,8 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
     /// instead.
     #[unstable(feature = "pin", issue = "49150")]
     #[inline(always)]
-    pub unsafe fn get_mut_unchecked(this: Pin<&'a mut T>) -> &'a mut T {
-        this.pointer
+    pub unsafe fn get_unchecked_mut(self: Pin<&'a mut T>) -> &'a mut T {
+        self.pointer
     }
 
     /// Construct a new pin by mapping the interior value.
@@ -275,10 +273,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
     /// because it is one of the fields of that value), and also that you do
     /// not move out of the argument you receive to the interior function.
     #[unstable(feature = "pin", issue = "49150")]
-    pub unsafe fn map_unchecked_mut<U, F>(this: Pin<&'a mut T>, func: F) -> Pin<&'a mut U> where
+    pub unsafe fn map_unchecked_mut<U, F>(self: Pin<&'a mut T>, func: F) -> Pin<&'a mut U> where
         F: FnOnce(&mut T) -> &mut U,
     {
-        let pointer = Pin::get_mut_unchecked(this);
+        let pointer = Pin::get_unchecked_mut(self);
         let new_pointer = func(pointer);
         Pin::new_unchecked(new_pointer)
     }
@@ -342,6 +340,3 @@ impl<'a, P, U> DispatchFromDyn<Pin<U>> for Pin<P>
 where
     P: DispatchFromDyn<U>,
 {}
-
-#[unstable(feature = "pin", issue = "49150")]
-impl<P> Unpin for Pin<P> {}
diff --git a/src/libcore/prelude/v1.rs b/src/libcore/prelude/v1.rs
index 45f629a6442..a1e6034b208 100644
--- a/src/libcore/prelude/v1.rs
+++ b/src/libcore/prelude/v1.rs
@@ -19,7 +19,7 @@
 // Re-exported core operators
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use marker::{Copy, Send, Sized, Sync};
+pub use marker::{Copy, Send, Sized, Sync, Unpin};
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
 pub use ops::{Drop, Fn, FnMut, FnOnce};
diff --git a/src/libstd/future.rs b/src/libstd/future.rs
index d5e6cab948b..3379be79186 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: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
-        set_task_waker(lw, || match unsafe { Pin::get_mut_unchecked(self).0.resume() } {
+        set_task_waker(lw, || match unsafe { Pin::get_unchecked_mut(self).0.resume() } {
             GeneratorState::Yielded(()) => Poll::Pending,
             GeneratorState::Complete(x) => Poll::Ready(x),
         })