Skip to content

Commit c2d4603

Browse files
committed
Auto merge of #50984 - cramertj:unpin-changes, r=aturon
Unpin changes r? @aturon cc @withoutboats, @RalfJung, @pythonesque, #49150
2 parents 0746522 + 15d2f96 commit c2d4603

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -850,4 +850,4 @@ impl<T: ?Sized> fmt::Pointer for PinBox<T> {
850850
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {}
851851

852852
#[unstable(feature = "pin", issue = "49150")]
853-
unsafe impl<T: ?Sized> Unpin for PinBox<T> {}
853+
impl<T: ?Sized> Unpin for PinBox<T> {}

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#![deny(missing_debug_implementations)]
7575

7676
#![feature(allow_internal_unstable)]
77+
#![feature(arbitrary_self_types)]
7778
#![feature(asm)]
7879
#![feature(associated_type_defaults)]
7980
#![feature(attr_literals)]

src/libcore/marker.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,17 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
605605
///
606606
/// [`PinMut`]: ../mem/struct.PinMut.html
607607
#[unstable(feature = "pin", issue = "49150")]
608-
pub unsafe auto trait Unpin {}
608+
pub auto trait Unpin {}
609+
610+
/// A type which does not implement `Unpin`.
611+
///
612+
/// If a type contains a `Pinned`, it will not implement `Unpin` by default.
613+
#[unstable(feature = "pin", issue = "49150")]
614+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
615+
pub struct Pinned;
616+
617+
#[unstable(feature = "pin", issue = "49150")]
618+
impl !Unpin for Pinned {}
609619

610620
/// Implementations of `Copy` for primitive types.
611621
///

src/libcore/mem.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,14 @@ impl<'a, T: ?Sized> PinMut<'a, T> {
11641164
{
11651165
PinMut { inner: f(this.inner) }
11661166
}
1167+
1168+
/// Assign a new value to the memory behind the pinned reference.
1169+
#[unstable(feature = "pin", issue = "49150")]
1170+
pub fn set(this: PinMut<'a, T>, value: T)
1171+
where T: Sized,
1172+
{
1173+
*this.inner = value;
1174+
}
11671175
}
11681176

11691177
#[unstable(feature = "pin", issue = "49150")]
@@ -1207,4 +1215,4 @@ impl<'a, T: ?Sized> fmt::Pointer for PinMut<'a, T> {
12071215
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinMut<'a, U>> for PinMut<'a, T> {}
12081216

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

src/libcore/option.rs

+10
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147

148148
use iter::{FromIterator, FusedIterator, TrustedLen};
149149
use {mem, ops};
150+
use mem::PinMut;
150151

151152
// Note that this is not a lang item per se, but it has a hidden dependency on
152153
// `Iterator`, which is one. The compiler assumes that the `next` method of
@@ -269,6 +270,15 @@ impl<T> Option<T> {
269270
}
270271
}
271272

273+
/// Converts from `Option<T>` to `Option<PinMut<'_, T>>`
274+
#[inline]
275+
#[unstable(feature = "pin", issue = "49150")]
276+
pub fn as_pin_mut<'a>(self: PinMut<'a, Self>) -> Option<PinMut<'a, T>> {
277+
unsafe {
278+
PinMut::get_mut(self).as_mut().map(|x| PinMut::new_unchecked(x))
279+
}
280+
}
281+
272282
/////////////////////////////////////////////////////////////////////////
273283
// Getting to contained values
274284
/////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)