Skip to content

Commit 148f172

Browse files
Rollup merge of rust-lang#56939 - cramertj:pin-stabilization, r=alexcrichton
Pin stabilization This implements the changes suggested in rust-lang#55766 (comment) and stabilizes the `pin` feature. @alexcrichton also listed several "blockers" in that issue, but then in [this comment](rust-lang#55766 (comment)) mentioned that they're more "TODO items": > In that vein I think it's fine for a stabilization PR to be posted at any time now with FCP lapsed for a week or so now. The final points about self/pin/pinned can be briefly discussed there (if even necessary, they could be left as the proposal above). Let's settle these last bits here and get this thing stabilized! :) r? @alexcrichton cc @withoutboats
2 parents 5bf6ba4 + 46a4ff6 commit 148f172

File tree

15 files changed

+69
-74
lines changed

15 files changed

+69
-74
lines changed

src/liballoc/boxed.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ impl<T> Box<T> {
109109
box x
110110
}
111111

112-
#[unstable(feature = "pin", issue = "49150")]
112+
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
113+
/// `x` will be pinned in memory and unable to be moved.
114+
#[stable(feature = "pin", since = "1.33.0")]
113115
#[inline(always)]
114-
pub fn pinned(x: T) -> Pin<Box<T>> {
116+
pub fn pin(x: T) -> Pin<Box<T>> {
115117
(box x).into()
116118
}
117119
}
@@ -444,7 +446,7 @@ impl<T> From<T> for Box<T> {
444446
}
445447
}
446448

447-
#[unstable(feature = "pin", issue = "49150")]
449+
#[stable(feature = "pin", since = "1.33.0")]
448450
impl<T> From<Box<T>> for Pin<Box<T>> {
449451
fn from(boxed: Box<T>) -> Self {
450452
// It's not possible to move or replace the insides of a `Pin<Box<T>>`
@@ -808,7 +810,7 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
808810
* implementation of `Unpin` (where `T: Unpin`) would be valid/safe, and
809811
* could have a method to project a Pin<T> from it.
810812
*/
811-
#[unstable(feature = "pin", issue = "49150")]
813+
#[stable(feature = "pin", since = "1.33.0")]
812814
impl<T: ?Sized> Unpin for Box<T> { }
813815

814816
#[unstable(feature = "generator_trait", issue = "43122")]

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
#![feature(nll)]
101101
#![feature(optin_builtin_traits)]
102102
#![feature(pattern)]
103-
#![feature(pin)]
104103
#![feature(ptr_internals)]
105104
#![feature(ptr_offset_from)]
106105
#![feature(rustc_attrs)]

src/liballoc/rc.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ impl<T> Rc<T> {
325325
}
326326
}
327327

328-
#[unstable(feature = "pin", issue = "49150")]
329-
pub fn pinned(value: T) -> Pin<Rc<T>> {
328+
/// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
329+
/// `value` will be pinned in memory and unable to be moved.
330+
#[stable(feature = "pin", since = "1.33.0")]
331+
pub fn pin(value: T) -> Pin<Rc<T>> {
330332
unsafe { Pin::new_unchecked(Rc::new(value)) }
331333
}
332334

@@ -1928,5 +1930,5 @@ impl<T: ?Sized> AsRef<T> for Rc<T> {
19281930
}
19291931
}
19301932

1931-
#[unstable(feature = "pin", issue = "49150")]
1933+
#[stable(feature = "pin", since = "1.33.0")]
19321934
impl<T: ?Sized> Unpin for Rc<T> { }

src/liballoc/sync.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,10 @@ impl<T> Arc<T> {
303303
Arc { ptr: Box::into_raw_non_null(x), phantom: PhantomData }
304304
}
305305

306-
#[unstable(feature = "pin", issue = "49150")]
307-
pub fn pinned(data: T) -> Pin<Arc<T>> {
306+
/// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
307+
/// `data` will be pinned in memory and unable to be moved.
308+
#[stable(feature = "pin", since = "1.33.0")]
309+
pub fn pin(data: T) -> Pin<Arc<T>> {
308310
unsafe { Pin::new_unchecked(Arc::new(data)) }
309311
}
310312

@@ -2044,5 +2046,5 @@ impl<T: ?Sized> AsRef<T> for Arc<T> {
20442046
}
20452047
}
20462048

2047-
#[unstable(feature = "pin", issue = "49150")]
2049+
#[stable(feature = "pin", since = "1.33.0")]
20482050
impl<T: ?Sized> Unpin for Arc<T> { }

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/marker.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
621621
/// So this, for example, can only be done on types implementing `Unpin`:
622622
///
623623
/// ```rust
624-
/// #![feature(pin)]
625624
/// use std::mem::replace;
626625
/// use std::pin::Pin;
627626
///
@@ -637,23 +636,23 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
637636
/// [`replace`]: ../../std/mem/fn.replace.html
638637
/// [`Pin`]: ../pin/struct.Pin.html
639638
/// [`pin module`]: ../../std/pin/index.html
640-
#[unstable(feature = "pin", issue = "49150")]
639+
#[stable(feature = "pin", since = "1.33.0")]
641640
pub auto trait Unpin {}
642641

643642
/// A marker type which does not implement `Unpin`.
644643
///
645644
/// If a type contains a `PhantomPinned`, it will not implement `Unpin` by default.
646-
#[unstable(feature = "pin", issue = "49150")]
645+
#[stable(feature = "pin", since = "1.33.0")]
647646
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
648647
pub struct PhantomPinned;
649648

650-
#[unstable(feature = "pin", issue = "49150")]
649+
#[stable(feature = "pin", since = "1.33.0")]
651650
impl !Unpin for PhantomPinned {}
652651

653-
#[unstable(feature = "pin", issue = "49150")]
652+
#[stable(feature = "pin", since = "1.33.0")]
654653
impl<'a, T: ?Sized + 'a> Unpin for &'a T {}
655654

656-
#[unstable(feature = "pin", issue = "49150")]
655+
#[stable(feature = "pin", since = "1.33.0")]
657656
impl<'a, T: ?Sized + 'a> Unpin for &'a mut T {}
658657

659658
/// Implementations of `Copy` for primitive types.

src/libcore/option.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<T> Option<T> {
273273

274274
/// Converts from `Pin<&Option<T>>` to `Option<Pin<&T>>`
275275
#[inline]
276-
#[unstable(feature = "pin", issue = "49150")]
276+
#[stable(feature = "pin", since = "1.33.0")]
277277
pub fn as_pin_ref<'a>(self: Pin<&'a Option<T>>) -> Option<Pin<&'a T>> {
278278
unsafe {
279279
Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x))
@@ -282,10 +282,10 @@ impl<T> Option<T> {
282282

283283
/// Converts from `Pin<&mut Option<T>>` to `Option<Pin<&mut T>>`
284284
#[inline]
285-
#[unstable(feature = "pin", issue = "49150")]
285+
#[stable(feature = "pin", since = "1.33.0")]
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

+37-44
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
//! are always freely movable, even if the data they point to isn't.
3737
//!
3838
//! [`Pin`]: struct.Pin.html
39-
//! [`Unpin`]: trait.Unpin.html
39+
//! [`Unpin`]: ../../std/marker/trait.Unpin.html
4040
//! [`swap`]: ../../std/mem/fn.swap.html
4141
//! [`Box`]: ../../std/boxed/struct.Box.html
4242
//!
4343
//! # Examples
4444
//!
4545
//! ```rust
46-
//! #![feature(pin)]
47-
//!
4846
//! use std::pin::Pin;
4947
//! use std::marker::PhantomPinned;
5048
//! use std::ptr::NonNull;
@@ -72,13 +70,13 @@
7270
//! slice: NonNull::dangling(),
7371
//! _pin: PhantomPinned,
7472
//! };
75-
//! let mut boxed = Box::pinned(res);
73+
//! let mut boxed = Box::pin(res);
7674
//!
7775
//! let slice = NonNull::from(&boxed.data);
7876
//! // we know this is safe because modifying a field doesn't move the whole struct
7977
//! unsafe {
8078
//! let mut_ref: Pin<&mut Self> = Pin::as_mut(&mut boxed);
81-
//! Pin::get_mut_unchecked(mut_ref).slice = slice;
79+
//! Pin::get_unchecked_mut(mut_ref).slice = slice;
8280
//! }
8381
//! boxed
8482
//! }
@@ -97,15 +95,12 @@
9795
//! // std::mem::swap(&mut *still_unmoved, &mut *new_unmoved);
9896
//! ```
9997
100-
#![unstable(feature = "pin", issue = "49150")]
98+
#![stable(feature = "pin", since = "1.33.0")]
10199

102100
use fmt;
103-
use marker::Sized;
101+
use marker::{Sized, Unpin};
104102
use ops::{Deref, DerefMut, CoerceUnsized, DispatchFromDyn};
105103

106-
#[doc(inline)]
107-
pub use marker::Unpin;
108-
109104
/// A pinned pointer.
110105
///
111106
/// This is a wrapper around a kind of pointer which makes that pointer "pin" its
@@ -119,8 +114,9 @@ pub use marker::Unpin;
119114
//
120115
// Note: the derives below are allowed because they all only use `&P`, so they
121116
// cannot move the value behind `pointer`.
122-
#[unstable(feature = "pin", issue = "49150")]
117+
#[stable(feature = "pin", since = "1.33.0")]
123118
#[fundamental]
119+
#[repr(transparent)]
124120
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
125121
pub struct Pin<P> {
126122
pointer: P,
@@ -132,7 +128,7 @@ where
132128
{
133129
/// Construct a new `Pin` around a pointer to some data of a type that
134130
/// implements `Unpin`.
135-
#[unstable(feature = "pin", issue = "49150")]
131+
#[stable(feature = "pin", since = "1.33.0")]
136132
#[inline(always)]
137133
pub fn new(pointer: P) -> Pin<P> {
138134
// Safety: the value pointed to is `Unpin`, and so has no requirements
@@ -154,14 +150,14 @@ impl<P: Deref> Pin<P> {
154150
///
155151
/// If `pointer` dereferences to an `Unpin` type, `Pin::new` should be used
156152
/// instead.
157-
#[unstable(feature = "pin", issue = "49150")]
153+
#[stable(feature = "pin", since = "1.33.0")]
158154
#[inline(always)]
159155
pub unsafe fn new_unchecked(pointer: P) -> Pin<P> {
160156
Pin { pointer }
161157
}
162158

163159
/// Get a pinned shared reference from this pinned pointer.
164-
#[unstable(feature = "pin", issue = "49150")]
160+
#[stable(feature = "pin", since = "1.33.0")]
165161
#[inline(always)]
166162
pub fn as_ref(self: &Pin<P>) -> Pin<&P::Target> {
167163
unsafe { Pin::new_unchecked(&*self.pointer) }
@@ -170,14 +166,14 @@ impl<P: Deref> Pin<P> {
170166

171167
impl<P: DerefMut> Pin<P> {
172168
/// Get a pinned mutable reference from this pinned pointer.
173-
#[unstable(feature = "pin", issue = "49150")]
169+
#[stable(feature = "pin", since = "1.33.0")]
174170
#[inline(always)]
175171
pub fn as_mut(self: &mut Pin<P>) -> Pin<&mut P::Target> {
176172
unsafe { Pin::new_unchecked(&mut *self.pointer) }
177173
}
178174

179175
/// Assign a new value to the memory behind the pinned reference.
180-
#[unstable(feature = "pin", issue = "49150")]
176+
#[stable(feature = "pin", since = "1.33.0")]
181177
#[inline(always)]
182178
pub fn set(mut self: Pin<P>, value: P::Target)
183179
where
@@ -199,11 +195,11 @@ impl<'a, T: ?Sized> Pin<&'a T> {
199195
/// will not move so long as the argument value does not move (for example,
200196
/// because it is one of the fields of that value), and also that you do
201197
/// not move out of the argument you receive to the interior function.
202-
#[unstable(feature = "pin", issue = "49150")]
203-
pub unsafe fn map_unchecked<U, F>(this: Pin<&'a T>, func: F) -> Pin<&'a U> where
198+
#[stable(feature = "pin", since = "1.33.0")]
199+
pub unsafe fn map_unchecked<U, F>(self: Pin<&'a T>, func: F) -> Pin<&'a U> where
204200
F: FnOnce(&T) -> &U,
205201
{
206-
let pointer = &*this.pointer;
202+
let pointer = &*self.pointer;
207203
let new_pointer = func(pointer);
208204
Pin::new_unchecked(new_pointer)
209205
}
@@ -215,19 +211,19 @@ impl<'a, T: ?Sized> Pin<&'a T> {
215211
/// that lives for as long as the borrow of the `Pin`, not the lifetime of
216212
/// the `Pin` itself. This method allows turning the `Pin` into a reference
217213
/// with the same lifetime as the original `Pin`.
218-
#[unstable(feature = "pin", issue = "49150")]
214+
#[stable(feature = "pin", since = "1.33.0")]
219215
#[inline(always)]
220-
pub fn get_ref(this: Pin<&'a T>) -> &'a T {
221-
this.pointer
216+
pub fn get_ref(self: Pin<&'a T>) -> &'a T {
217+
self.pointer
222218
}
223219
}
224220

225221
impl<'a, T: ?Sized> Pin<&'a mut T> {
226222
/// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
227-
#[unstable(feature = "pin", issue = "49150")]
223+
#[stable(feature = "pin", since = "1.33.0")]
228224
#[inline(always)]
229-
pub fn into_ref(this: Pin<&'a mut T>) -> Pin<&'a T> {
230-
Pin { pointer: this.pointer }
225+
pub fn into_ref(self: Pin<&'a mut T>) -> Pin<&'a T> {
226+
Pin { pointer: self.pointer }
231227
}
232228

233229
/// Get a mutable reference to the data inside of this `Pin`.
@@ -239,12 +235,12 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
239235
/// that lives for as long as the borrow of the `Pin`, not the lifetime of
240236
/// the `Pin` itself. This method allows turning the `Pin` into a reference
241237
/// with the same lifetime as the original `Pin`.
242-
#[unstable(feature = "pin", issue = "49150")]
238+
#[stable(feature = "pin", since = "1.33.0")]
243239
#[inline(always)]
244-
pub fn get_mut(this: Pin<&'a mut T>) -> &'a mut T
240+
pub fn get_mut(self: Pin<&'a mut T>) -> &'a mut T
245241
where T: Unpin,
246242
{
247-
this.pointer
243+
self.pointer
248244
}
249245

250246
/// Get a mutable reference to the data inside of this `Pin`.
@@ -257,10 +253,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
257253
///
258254
/// If the underlying data is `Unpin`, `Pin::get_mut` should be used
259255
/// instead.
260-
#[unstable(feature = "pin", issue = "49150")]
256+
#[stable(feature = "pin", since = "1.33.0")]
261257
#[inline(always)]
262-
pub unsafe fn get_mut_unchecked(this: Pin<&'a mut T>) -> &'a mut T {
263-
this.pointer
258+
pub unsafe fn get_unchecked_mut(self: Pin<&'a mut T>) -> &'a mut T {
259+
self.pointer
264260
}
265261

266262
/// Construct a new pin by mapping the interior value.
@@ -274,25 +270,25 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
274270
/// will not move so long as the argument value does not move (for example,
275271
/// because it is one of the fields of that value), and also that you do
276272
/// not move out of the argument you receive to the interior function.
277-
#[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
273+
#[stable(feature = "pin", since = "1.33.0")]
274+
pub unsafe fn map_unchecked_mut<U, F>(self: Pin<&'a mut T>, func: F) -> Pin<&'a mut U> where
279275
F: FnOnce(&mut T) -> &mut U,
280276
{
281-
let pointer = Pin::get_mut_unchecked(this);
277+
let pointer = Pin::get_unchecked_mut(self);
282278
let new_pointer = func(pointer);
283279
Pin::new_unchecked(new_pointer)
284280
}
285281
}
286282

287-
#[unstable(feature = "pin", issue = "49150")]
283+
#[stable(feature = "pin", since = "1.33.0")]
288284
impl<P: Deref> Deref for Pin<P> {
289285
type Target = P::Target;
290286
fn deref(&self) -> &P::Target {
291287
Pin::get_ref(Pin::as_ref(self))
292288
}
293289
}
294290

295-
#[unstable(feature = "pin", issue = "49150")]
291+
#[stable(feature = "pin", since = "1.33.0")]
296292
impl<P: DerefMut> DerefMut for Pin<P>
297293
where
298294
P::Target: Unpin
@@ -302,21 +298,21 @@ where
302298
}
303299
}
304300

305-
#[unstable(feature = "pin", issue = "49150")]
301+
#[stable(feature = "pin", since = "1.33.0")]
306302
impl<P: fmt::Debug> fmt::Debug for Pin<P> {
307303
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
308304
fmt::Debug::fmt(&self.pointer, f)
309305
}
310306
}
311307

312-
#[unstable(feature = "pin", issue = "49150")]
308+
#[stable(feature = "pin", since = "1.33.0")]
313309
impl<P: fmt::Display> fmt::Display for Pin<P> {
314310
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
315311
fmt::Display::fmt(&self.pointer, f)
316312
}
317313
}
318314

319-
#[unstable(feature = "pin", issue = "49150")]
315+
#[stable(feature = "pin", since = "1.33.0")]
320316
impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
321317
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
322318
fmt::Pointer::fmt(&self.pointer, f)
@@ -328,17 +324,14 @@ impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
328324
// `Deref<Target=Unpin>` is unsound. Any such impl would probably be unsound
329325
// for other reasons, though, so we just need to take care not to allow such
330326
// impls to land in std.
331-
#[unstable(feature = "pin", issue = "49150")]
327+
#[stable(feature = "pin", since = "1.33.0")]
332328
impl<P, U> CoerceUnsized<Pin<U>> for Pin<P>
333329
where
334330
P: CoerceUnsized<U>,
335331
{}
336332

337-
#[unstable(feature = "pin", issue = "49150")]
333+
#[stable(feature = "pin", since = "1.33.0")]
338334
impl<'a, P, U> DispatchFromDyn<Pin<U>> for Pin<P>
339335
where
340336
P: DispatchFromDyn<U>,
341337
{}
342-
343-
#[unstable(feature = "pin", issue = "49150")]
344-
impl<P> Unpin for Pin<P> {}

0 commit comments

Comments
 (0)