Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpin changes #50984

Merged
merged 4 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,4 @@ impl<T: ?Sized> fmt::Pointer for PinBox<T> {
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {}

#[unstable(feature = "pin", issue = "49150")]
unsafe impl<T: ?Sized> Unpin for PinBox<T> {}
impl<T: ?Sized> Unpin for PinBox<T> {}
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#![deny(missing_debug_implementations)]

#![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)]
#![feature(asm)]
#![feature(associated_type_defaults)]
#![feature(attr_literals)]
Expand Down
12 changes: 11 additions & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,17 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
///
/// [`PinMut`]: ../mem/struct.PinMut.html
#[unstable(feature = "pin", issue = "49150")]
pub unsafe auto trait Unpin {}
pub auto trait Unpin {}

/// A type which does not implement `Unpin`.
///
/// If a type contains a `Pinned`, it will not implement `Unpin` by default.
#[unstable(feature = "pin", issue = "49150")]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Pinned;

#[unstable(feature = "pin", issue = "49150")]
impl !Unpin for Pinned {}

/// Implementations of `Copy` for primitive types.
///
Expand Down
10 changes: 9 additions & 1 deletion src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,14 @@ impl<'a, T: ?Sized> PinMut<'a, T> {
{
PinMut { inner: f(this.inner) }
}

/// Assign a new value to the memory behind the pinned reference.
#[unstable(feature = "pin", issue = "49150")]
pub fn set(this: PinMut<'a, T>, value: T)
where T: Sized,
{
*this.inner = value;
}
}

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

#[unstable(feature = "pin", issue = "49150")]
unsafe impl<'a, T: ?Sized> Unpin for PinMut<'a, T> {}
impl<'a, T: ?Sized> Unpin for PinMut<'a, T> {}
10 changes: 10 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@

use iter::{FromIterator, FusedIterator, TrustedLen};
use {mem, ops};
use mem::PinMut;

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

/// Converts from `Option<T>` to `Option<PinMut<'_, T>>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should say "from PinMut<'_, Option<T> to".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case, we should better change the docs of as_ref() and as_mut() as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think that would make sense, though.

#[inline]
#[unstable(feature = "pin", issue = "49150")]
pub fn as_pin_mut<'a>(self: PinMut<'a, Self>) -> Option<PinMut<'a, T>> {
unsafe {
PinMut::get_mut(self).as_mut().map(|x| PinMut::new_unchecked(x))
}
}

/////////////////////////////////////////////////////////////////////////
// Getting to contained values
/////////////////////////////////////////////////////////////////////////
Expand Down