Skip to content

Commit 974bdc8

Browse files
author
Without Boats
committed
Update to a new pinning API.
1 parent e6b35b0 commit 974bdc8

File tree

14 files changed

+309
-420
lines changed

14 files changed

+309
-420
lines changed

src/liballoc/boxed.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ use core::hash::{Hash, Hasher};
6565
use core::iter::FusedIterator;
6666
use core::marker::{Unpin, Unsize};
6767
use core::mem;
68-
use core::pin::PinMut;
68+
use core::pin::Pin;
6969
use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
7070
use core::ptr::{self, NonNull, Unique};
7171
use core::task::{Context, Poll, Spawn, SpawnErrorKind, SpawnObjError};
7272

7373
use raw_vec::RawVec;
74-
use pin::PinBox;
7574
use str::from_boxed_utf8_unchecked;
7675

7776
/// A pointer type for heap allocation.
@@ -97,6 +96,11 @@ impl<T> Box<T> {
9796
pub fn new(x: T) -> Box<T> {
9897
box x
9998
}
99+
100+
#[unstable(feature = "pin", issue = "49150")]
101+
pub fn pinned(x: T) -> Pin<Box<T>> {
102+
unsafe { Pin::new_unchecked(box x) }
103+
}
100104
}
101105

102106
impl<T: ?Sized> Box<T> {
@@ -427,6 +431,13 @@ impl<T> From<T> for Box<T> {
427431
}
428432
}
429433

434+
#[unstable(feature = "pin", issue = "49150")]
435+
impl<T> From<Box<T>> for Pin<Box<T>> {
436+
fn from(boxed: Box<T>) -> Self {
437+
unsafe { Pin::new_unchecked(boxed) }
438+
}
439+
}
440+
430441
#[stable(feature = "box_from_slice", since = "1.17.0")]
431442
impl<'a, T: Copy> From<&'a [T]> for Box<[T]> {
432443
fn from(slice: &'a [T]) -> Box<[T]> {
@@ -764,8 +775,8 @@ impl<T> Generator for Box<T>
764775
impl<F: ?Sized + Future + Unpin> Future for Box<F> {
765776
type Output = F::Output;
766777

767-
fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
768-
PinMut::new(&mut **self).poll(cx)
778+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
779+
F::poll(Pin::new(&mut *self), cx)
769780
}
770781
}
771782

@@ -779,8 +790,8 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F>
779790

780791
unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll<T> {
781792
let ptr = ptr as *mut F;
782-
let pin: PinMut<F> = PinMut::new_unchecked(&mut *ptr);
783-
pin.poll(cx)
793+
let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr);
794+
F::poll(pin, cx)
784795
}
785796

786797
unsafe fn drop(ptr: *mut ()) {
@@ -818,9 +829,16 @@ impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> {
818829
}
819830
}
820831

821-
#[unstable(feature = "pin", issue = "49150")]
822-
impl<T: Unpin + ?Sized> From<PinBox<T>> for Box<T> {
823-
fn from(pinned: PinBox<T>) -> Box<T> {
824-
unsafe { PinBox::unpin(pinned) }
832+
#[unstable(feature = "futures_api", issue = "50547")]
833+
impl<'a, F: Future<Output = ()> + Send + 'a> From<Pin<Box<F>>> for FutureObj<'a, ()> {
834+
fn from(boxed: Pin<Box<F>>) -> Self {
835+
FutureObj::new(boxed)
836+
}
837+
}
838+
839+
#[unstable(feature = "futures_api", issue = "50547")]
840+
impl<'a, F: Future<Output = ()> + 'a> From<Pin<Box<F>>> for LocalFutureObj<'a, ()> {
841+
fn from(boxed: Pin<Box<F>>) -> Self {
842+
LocalFutureObj::new(boxed)
825843
}
826844
}

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ pub mod collections;
160160
pub mod sync;
161161
pub mod rc;
162162
pub mod raw_vec;
163-
pub mod pin;
164163
pub mod prelude;
165164
pub mod borrow;
166165
pub mod fmt;

src/liballoc/pin.rs

-302
This file was deleted.

0 commit comments

Comments
 (0)