Skip to content

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed
 

‎src/libcore/marker.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -640,15 +640,15 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
640640
#[unstable(feature = "pin", issue = "49150")]
641641
pub auto trait Unpin {}
642642

643-
/// A type which does not implement `Unpin`.
643+
/// A marker type which does not implement `Unpin`.
644644
///
645-
/// If a type contains a `Pinned`, it will not implement `Unpin` by default.
645+
/// If a type contains a `PhantomPinned`, it will not implement `Unpin` by default.
646646
#[unstable(feature = "pin", issue = "49150")]
647647
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
648-
pub struct Pinned;
648+
pub struct PhantomPinned;
649649

650650
#[unstable(feature = "pin", issue = "49150")]
651-
impl !Unpin for Pinned {}
651+
impl !Unpin for PhantomPinned {}
652652

653653
#[unstable(feature = "pin", issue = "49150")]
654654
impl<'a, T: ?Sized + 'a> Unpin for &'a T {}

‎src/libcore/pin.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
//! Since data can be moved out of `&mut` and `Box` with functions such as [`swap`],
2020
//! changing the location of the underlying data, [`Pin`] prohibits accessing the
2121
//! underlying pointer type (the `&mut` or `Box`) directly, and provides its own set of
22-
//! APIs for accessing and using the value.
22+
//! APIs for accessing and using the value. [`Pin`] also guarantees that no other
23+
//! functions will move the pointed-to value. This allows for the creation of
24+
//! self-references and other special behaviors that are only possible for unmovable
25+
//! values.
2326
//!
2427
//! However, these restrictions are usually not necessary. Many types are always freely
2528
//! movable. These types implement the [`Unpin`] auto-trait, which nullifies the affect
@@ -43,7 +46,7 @@
4346
//! #![feature(pin)]
4447
//!
4548
//! use std::pin::Pin;
46-
//! use std::marker::Pinned;
49+
//! use std::marker::PhantomPinned;
4750
//! use std::ptr::NonNull;
4851
//!
4952
//! // This is a self-referential struct since the slice field points to the data field.
@@ -54,7 +57,7 @@
5457
//! struct Unmovable {
5558
//! data: String,
5659
//! slice: NonNull<String>,
57-
//! _pin: Pinned,
60+
//! _pin: PhantomPinned,
5861
//! }
5962
//!
6063
//! impl Unmovable {
@@ -67,7 +70,7 @@
6770
//! // we only create the pointer once the data is in place
6871
//! // otherwise it will have already moved before we even started
6972
//! slice: NonNull::dangling(),
70-
//! _pin: Pinned,
73+
//! _pin: PhantomPinned,
7174
//! };
7275
//! let mut boxed = Box::pinned(res);
7376
//!

0 commit comments

Comments
 (0)
Please sign in to comment.