Skip to content

Commit 9f26376

Browse files
committed
Rename Pin to PinMut
As discussed at [1] §3 and [2] and [3], a formal look at pinning requires considering a distinguished "shared pinned" mode/typestate. Given that, it seems desirable to at least eventually actually expose that typestate as a reference type. This renames Pin to PinMut, freeing the name Pin in case we want to use it for a shared pinned reference later on. [1] https://www.ralfj.de/blog/2018/04/10/safe-intrusive-collections-with-pinning.html [2] rust-lang/rfcs#2349 (comment) [3] #49150 (comment)
1 parent 9b97705 commit 9f26376

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/liballoc/boxed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use core::fmt;
6262
use core::hash::{Hash, Hasher};
6363
use core::iter::FusedIterator;
6464
use core::marker::{Unpin, Unsize};
65-
use core::mem::{self, Pin};
65+
use core::mem::{self, PinMut};
6666
use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
6767
use core::ptr::{self, NonNull, Unique};
6868
use core::convert::From;
@@ -771,8 +771,8 @@ impl<T> PinBox<T> {
771771
#[unstable(feature = "pin", issue = "49150")]
772772
impl<T: ?Sized> PinBox<T> {
773773
/// Get a pinned reference to the data in this PinBox.
774-
pub fn as_pin<'a>(&'a mut self) -> Pin<'a, T> {
775-
unsafe { Pin::new_unchecked(&mut *self.inner) }
774+
pub fn as_pin_mut<'a>(&'a mut self) -> PinMut<'a, T> {
775+
unsafe { PinMut::new_unchecked(&mut *self.inner) }
776776
}
777777

778778
/// Get a mutable reference to the data inside this PinBox.

src/libcore/mem.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -1101,69 +1101,69 @@ impl<T: ::hash::Hash> ::hash::Hash for ManuallyDrop<T> {
11011101
/// value implements the `Unpin` trait.
11021102
#[unstable(feature = "pin", issue = "49150")]
11031103
#[fundamental]
1104-
pub struct Pin<'a, T: ?Sized + 'a> {
1104+
pub struct PinMut<'a, T: ?Sized + 'a> {
11051105
inner: &'a mut T,
11061106
}
11071107

11081108
#[unstable(feature = "pin", issue = "49150")]
1109-
impl<'a, T: ?Sized + Unpin> Pin<'a, T> {
1110-
/// Construct a new `Pin` around a reference to some data of a type that
1109+
impl<'a, T: ?Sized + Unpin> PinMut<'a, T> {
1110+
/// Construct a new `PinMut` around a reference to some data of a type that
11111111
/// implements `Unpin`.
11121112
#[unstable(feature = "pin", issue = "49150")]
1113-
pub fn new(reference: &'a mut T) -> Pin<'a, T> {
1114-
Pin { inner: reference }
1113+
pub fn new(reference: &'a mut T) -> PinMut<'a, T> {
1114+
PinMut { inner: reference }
11151115
}
11161116
}
11171117

11181118

11191119
#[unstable(feature = "pin", issue = "49150")]
1120-
impl<'a, T: ?Sized> Pin<'a, T> {
1121-
/// Construct a new `Pin` around a reference to some data of a type that
1120+
impl<'a, T: ?Sized> PinMut<'a, T> {
1121+
/// Construct a new `PinMut` around a reference to some data of a type that
11221122
/// may or may not implement `Unpin`.
11231123
///
11241124
/// This constructor is unsafe because we do not know what will happen with
11251125
/// that data after the reference ends. If you cannot guarantee that the
11261126
/// data will never move again, calling this constructor is invalid.
11271127
#[unstable(feature = "pin", issue = "49150")]
1128-
pub unsafe fn new_unchecked(reference: &'a mut T) -> Pin<'a, T> {
1129-
Pin { inner: reference }
1128+
pub unsafe fn new_unchecked(reference: &'a mut T) -> PinMut<'a, T> {
1129+
PinMut { inner: reference }
11301130
}
11311131

1132-
/// Borrow a Pin for a shorter lifetime than it already has.
1132+
/// Borrow a PinMut for a shorter lifetime than it already has.
11331133
#[unstable(feature = "pin", issue = "49150")]
1134-
pub fn borrow<'b>(this: &'b mut Pin<'a, T>) -> Pin<'b, T> {
1135-
Pin { inner: this.inner }
1134+
pub fn borrow<'b>(this: &'b mut PinMut<'a, T>) -> PinMut<'b, T> {
1135+
PinMut { inner: this.inner }
11361136
}
11371137

1138-
/// Get a mutable reference to the data inside of this `Pin`.
1138+
/// Get a mutable reference to the data inside of this `PinMut`.
11391139
///
11401140
/// This function is unsafe. You must guarantee that you will never move
11411141
/// the data out of the mutable reference you receive when you call this
11421142
/// function.
11431143
#[unstable(feature = "pin", issue = "49150")]
1144-
pub unsafe fn get_mut<'b>(this: &'b mut Pin<'a, T>) -> &'b mut T {
1144+
pub unsafe fn get_mut<'b>(this: &'b mut PinMut<'a, T>) -> &'b mut T {
11451145
this.inner
11461146
}
11471147

11481148
/// Construct a new pin by mapping the interior value.
11491149
///
1150-
/// For example, if you wanted to get a `Pin` of a field of something, you
1150+
/// For example, if you wanted to get a `PinMut` of a field of something, you
11511151
/// could use this to get access to that field in one line of code.
11521152
///
11531153
/// This function is unsafe. You must guarantee that the data you return
11541154
/// will not move so long as the argument value does not move (for example,
11551155
/// because it is one of the fields of that value), and also that you do
11561156
/// not move out of the argument you receive to the interior function.
11571157
#[unstable(feature = "pin", issue = "49150")]
1158-
pub unsafe fn map<'b, U, F>(this: &'b mut Pin<'a, T>, f: F) -> Pin<'b, U> where
1158+
pub unsafe fn map<'b, U, F>(this: &'b mut PinMut<'a, T>, f: F) -> PinMut<'b, U> where
11591159
F: FnOnce(&mut T) -> &mut U
11601160
{
1161-
Pin { inner: f(this.inner) }
1161+
PinMut { inner: f(this.inner) }
11621162
}
11631163
}
11641164

11651165
#[unstable(feature = "pin", issue = "49150")]
1166-
impl<'a, T: ?Sized> Deref for Pin<'a, T> {
1166+
impl<'a, T: ?Sized> Deref for PinMut<'a, T> {
11671167
type Target = T;
11681168

11691169
fn deref(&self) -> &T {
@@ -1172,35 +1172,35 @@ impl<'a, T: ?Sized> Deref for Pin<'a, T> {
11721172
}
11731173

11741174
#[unstable(feature = "pin", issue = "49150")]
1175-
impl<'a, T: ?Sized + Unpin> DerefMut for Pin<'a, T> {
1175+
impl<'a, T: ?Sized + Unpin> DerefMut for PinMut<'a, T> {
11761176
fn deref_mut(&mut self) -> &mut T {
11771177
self.inner
11781178
}
11791179
}
11801180

11811181
#[unstable(feature = "pin", issue = "49150")]
1182-
impl<'a, T: fmt::Debug + ?Sized> fmt::Debug for Pin<'a, T> {
1182+
impl<'a, T: fmt::Debug + ?Sized> fmt::Debug for PinMut<'a, T> {
11831183
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11841184
fmt::Debug::fmt(&**self, f)
11851185
}
11861186
}
11871187

11881188
#[unstable(feature = "pin", issue = "49150")]
1189-
impl<'a, T: fmt::Display + ?Sized> fmt::Display for Pin<'a, T> {
1189+
impl<'a, T: fmt::Display + ?Sized> fmt::Display for PinMut<'a, T> {
11901190
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11911191
fmt::Display::fmt(&**self, f)
11921192
}
11931193
}
11941194

11951195
#[unstable(feature = "pin", issue = "49150")]
1196-
impl<'a, T: ?Sized> fmt::Pointer for Pin<'a, T> {
1196+
impl<'a, T: ?Sized> fmt::Pointer for PinMut<'a, T> {
11971197
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11981198
fmt::Pointer::fmt(&(&*self.inner as *const T), f)
11991199
}
12001200
}
12011201

12021202
#[unstable(feature = "pin", issue = "49150")]
1203-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Pin<'a, U>> for Pin<'a, T> {}
1203+
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinMut<'a, U>> for PinMut<'a, T> {}
12041204

12051205
#[unstable(feature = "pin", issue = "49150")]
1206-
unsafe impl<'a, T: ?Sized> Unpin for Pin<'a, T> {}
1206+
unsafe impl<'a, T: ?Sized> Unpin for PinMut<'a, T> {}

0 commit comments

Comments
 (0)