Skip to content

Commit 20d694a

Browse files
committed
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)
1 parent abaa934 commit 20d694a

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

src/libcore/future/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F {
120120

121121
impl<P> Future for Pin<P>
122122
where
123-
P: ops::DerefMut,
123+
P: Unpin + ops::DerefMut,
124124
P::Target: Future,
125125
{
126126
type Output = <<P as ops::Deref>::Target as Future>::Output;

src/libcore/option.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<T> Option<T> {
285285
#[unstable(feature = "pin", issue = "49150")]
286286
pub fn as_pin_mut<'a>(self: Pin<&'a mut Option<T>>) -> Option<Pin<&'a mut T>> {
287287
unsafe {
288-
Pin::get_mut_unchecked(self).as_mut().map(|x| Pin::new_unchecked(x))
288+
Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x))
289289
}
290290
}
291291

src/libcore/pin.rs

+14-19
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,9 @@
100100
#![unstable(feature = "pin", issue = "49150")]
101101

102102
use fmt;
103-
use marker::Sized;
103+
use marker::{Sized, Unpin};
104104
use ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
105105

106-
#[doc(inline)]
107-
pub use marker::Unpin;
108-
109106
/// A pinned pointer.
110107
///
111108
/// This is a wrapper around a kind of pointer which makes that pointer "pin" its
@@ -121,6 +118,7 @@ pub use marker::Unpin;
121118
// cannot move the value behind `pointer`.
122119
#[unstable(feature = "pin", issue = "49150")]
123120
#[fundamental]
121+
#[repr(transparent)]
124122
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
125123
pub struct Pin<P> {
126124
pointer: P,
@@ -200,10 +198,10 @@ impl<'a, T: ?Sized> Pin<&'a T> {
200198
/// because it is one of the fields of that value), and also that you do
201199
/// not move out of the argument you receive to the interior function.
202200
#[unstable(feature = "pin", issue = "49150")]
203-
pub unsafe fn map_unchecked<U, F>(this: Pin<&'a T>, func: F) -> Pin<&'a U> where
201+
pub unsafe fn map_unchecked<U, F>(self: Pin<&'a T>, func: F) -> Pin<&'a U> where
204202
F: FnOnce(&T) -> &U,
205203
{
206-
let pointer = &*this.pointer;
204+
let pointer = &*self.pointer;
207205
let new_pointer = func(pointer);
208206
Pin::new_unchecked(new_pointer)
209207
}
@@ -217,17 +215,17 @@ impl<'a, T: ?Sized> Pin<&'a T> {
217215
/// with the same lifetime as the original `Pin`.
218216
#[unstable(feature = "pin", issue = "49150")]
219217
#[inline(always)]
220-
pub fn get_ref(this: Pin<&'a T>) -> &'a T {
221-
this.pointer
218+
pub fn get_ref(self: Pin<&'a T>) -> &'a T {
219+
self.pointer
222220
}
223221
}
224222

225223
impl<'a, T: ?Sized> Pin<&'a mut T> {
226224
/// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
227225
#[unstable(feature = "pin", issue = "49150")]
228226
#[inline(always)]
229-
pub fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> {
230-
Pin { pointer: this.pointer }
227+
pub fn into_ref(self: Pin<&'a mut T>) -> Pin<&'a T> {
228+
Pin { pointer: self.pointer }
231229
}
232230

233231
/// Get a mutable reference to the data inside of this `Pin`.
@@ -241,10 +239,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
241239
/// with the same lifetime as the original `Pin`.
242240
#[unstable(feature = "pin", issue = "49150")]
243241
#[inline(always)]
244-
pub fn get_mut(this: Pin<&'a mut T>) -> &'a mut T
242+
pub fn get_mut(self: Pin<&'a mut T>) -> &'a mut T
245243
where T: Unpin,
246244
{
247-
this.pointer
245+
self.pointer
248246
}
249247

250248
/// Get a mutable reference to the data inside of this `Pin`.
@@ -259,8 +257,8 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
259257
/// instead.
260258
#[unstable(feature = "pin", issue = "49150")]
261259
#[inline(always)]
262-
pub unsafe fn get_mut_unchecked(this: Pin<&'a mut T>) -> &'a mut T {
263-
this.pointer
260+
pub unsafe fn get_unchecked_mut(self: Pin<&'a mut T>) -> &'a mut T {
261+
self.pointer
264262
}
265263

266264
/// Construct a new pin by mapping the interior value.
@@ -275,10 +273,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
275273
/// because it is one of the fields of that value), and also that you do
276274
/// not move out of the argument you receive to the interior function.
277275
#[unstable(feature = "pin", issue = "49150")]
278-
pub unsafe fn map_unchecked_mut<U, F>(this: Pin<&'a mut T>, func: F) -> Pin<&'a mut U> where
276+
pub unsafe fn map_unchecked_mut<U, F>(self: Pin<&'a mut T>, func: F) -> Pin<&'a mut U> where
279277
F: FnOnce(&mut T) -> &mut U,
280278
{
281-
let pointer = Pin::get_mut_unchecked(this);
279+
let pointer = Pin::get_unchecked_mut(self);
282280
let new_pointer = func(pointer);
283281
Pin::new_unchecked(new_pointer)
284282
}
@@ -342,6 +340,3 @@ impl<'a, P, U> DispatchFromDyn<Pin<U>> for Pin<P>
342340
where
343341
P: DispatchFromDyn<U>,
344342
{}
345-
346-
#[unstable(feature = "pin", issue = "49150")]
347-
impl<P> Unpin for Pin<P> {}

src/libcore/prelude/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Re-exported core operators
2020
#[stable(feature = "core_prelude", since = "1.4.0")]
2121
#[doc(no_inline)]
22-
pub use marker::{Copy, Send, Sized, Sync};
22+
pub use marker::{Copy, Send, Sized, Sync, Unpin};
2323
#[stable(feature = "core_prelude", since = "1.4.0")]
2424
#[doc(no_inline)]
2525
pub use ops::{Drop, Fn, FnMut, FnOnce};

src/libstd/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<T: Generator<Yield = ()>> !Unpin for GenFuture<T> {}
4343
impl<T: Generator<Yield = ()>> Future for GenFuture<T> {
4444
type Output = T::Return;
4545
fn poll(self: Pin<&mut Self>, lw: &LocalWaker) -> Poll<Self::Output> {
46-
set_task_waker(lw, || match unsafe { Pin::get_mut_unchecked(self).0.resume() } {
46+
set_task_waker(lw, || match unsafe { Pin::get_unchecked_mut(self).0.resume() } {
4747
GeneratorState::Yielded(()) => Poll::Pending,
4848
GeneratorState::Complete(x) => Poll::Ready(x),
4949
})

0 commit comments

Comments
 (0)