Skip to content

Update for latest nightly changes to rename Pin to PinMut #1003

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

Merged
merged 2 commits into from
May 10, 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
8 changes: 4 additions & 4 deletions futures-async-runtime/src/future.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::marker::Unpin;
use std::mem::Pin;
use std::mem::PinMut;
use std::ops::{Generator, GeneratorState};

use super::{IsResult, Reset, CTX};
Expand All @@ -25,12 +25,12 @@ impl<T> StableFuture for GenStableFuture<T>
type Item = <T::Return as IsResult>::Ok;
type Error = <T::Return as IsResult>::Err;

fn poll(mut self: Pin<Self>, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
fn poll(self: PinMut<Self>, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
CTX.with(|cell| {
let _r = Reset::new(ctx, cell);
let this: &mut Self = unsafe { Pin::get_mut(&mut self) };
let this: &mut Self = unsafe { PinMut::get_mut(self) };
// This is an immovable generator, but since we're only accessing
// it via a Pin this is safe.
// it via a PinMut this is safe.
match unsafe { this.0.resume() } {
GeneratorState::Yielded(Async::Pending)
=> Ok(Async::Pending),
Expand Down
8 changes: 4 additions & 4 deletions futures-async-runtime/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::mem::Pin;
use std::mem::PinMut;
use std::ops::{Generator, GeneratorState};
use std::marker::{PhantomData, Unpin};

Expand Down Expand Up @@ -37,13 +37,13 @@ impl<U, T> StableStream for GenStableStream<U, T>
type Item = U;
type Error = <T::Return as IsResult>::Err;

fn poll_next(mut self: Pin<Self>, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
fn poll_next(self: PinMut<Self>, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
CTX.with(|cell| {
let _r = Reset::new(ctx, cell);
let this: &mut Self = unsafe { Pin::get_mut(&mut self) };
let this: &mut Self = unsafe { PinMut::get_mut(self) };
if this.done { return Ok(Async::Ready(None)) }
// This is an immovable generator, but since we're only accessing
// it via a Pin this is safe.
// it via a PinMut this is safe.
match unsafe { this.gen.resume() } {
GeneratorState::Yielded(Async::Ready(e)) => {
Ok(Async::Ready(Some(e)))
Expand Down
4 changes: 2 additions & 2 deletions futures-channel/src/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! Similarly to the `std`, channel creation provides [`Receiver`](Receiver) and
//! [`Sender`](Sender) handles. [`Receiver`](Receiver) implements
//! [`Stream`](futures_core::Stream) and allows a task to read values out of the
//! [`Stream`] and allows a task to read values out of the
//! channel. If there is no message to read from the channel, the current task
//! will be awoken when a new value is sent. [`Sender`](Sender) implements the
//! `Sink` trait and allows a task to send messages into
Expand Down Expand Up @@ -333,7 +333,7 @@ impl SenderWaker {
/// `buffer` "first come, first serve" slots available to all senders.
///
/// The [`Receiver`](Receiver) returned implements the
/// [`Stream`](futures_core::Stream) trait, while [`Sender`](Sender) implements
/// [`Stream`] trait, while [`Sender`](Sender) implements
/// `Sink`.
pub fn channel<T>(buffer: usize) -> (Sender<T>, Receiver<T>) {
// Check that the requested buffer size does not exceed the maximum buffer
Expand Down
2 changes: 1 addition & 1 deletion futures-core/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if_std! {
type Error = F::Error;

fn poll(&mut self, cx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
unsafe { ::core::mem::Pin::get_mut(&mut self.as_pin()).poll(cx) }
unsafe { ::core::mem::PinMut::get_mut(self.as_pin_mut()).poll(cx) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion futures-core/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if_std! {
type Error = S::Error;

fn poll_next(&mut self, cx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
unsafe { ::core::mem::Pin::get_mut(&mut self.as_pin()).poll_next(cx) }
unsafe { ::core::mem::PinMut::get_mut(self.as_pin_mut()).poll_next(cx) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion futures-macro-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ if_nightly! {
let #pat = {
let r = {
let pin = unsafe {
::futures::__rt::std::mem::Pin::new_unchecked(&mut __stream)
::futures::__rt::std::mem::PinMut::new_unchecked(&mut __stream)
};
::futures::__rt::in_ctx(|ctx| ::futures::__rt::StableStream::poll_next(pin, ctx))
};
Expand Down
4 changes: 2 additions & 2 deletions futures-macro-await/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ macro_rules! await {
let future = &mut future;
// The above borrow is necessary to force a borrow across a
// yield point, proving that we're currently in an immovable
// generator, making the below `Pin::new_unchecked` call
// generator, making the below `PinMut::new_unchecked` call
// safe.
loop {
let poll = ::futures::__rt::in_ctx(|ctx| {
let pin = unsafe {
::futures::__rt::std::mem::Pin::new_unchecked(future)
::futures::__rt::std::mem::PinMut::new_unchecked(future)
};
::futures::__rt::StableFuture::poll(pin, ctx)
});
Expand Down
22 changes: 11 additions & 11 deletions futures-stable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if_nightly! {
extern crate futures_core;
extern crate futures_executor;

use core::mem::Pin;
use core::mem::PinMut;
use futures_core::{Future, Stream, Poll, task};

if_std! {
Expand All @@ -37,7 +37,7 @@ if_nightly! {

/// A trait for `Future`s which can be pinned to a particular location in memory.
///
/// These futures take `self` by `Pin<Self>`, rather than `&mut Self`.
/// These futures take `self` by `PinMut<Self>`, rather than `&mut Self`.
/// This allows types which are not [`Unpin`](::std::marker::Unpin) to guarantee
/// that they won't be moved after being polled. Since they won't be moved, it's
/// possible for them to safely contain references to themselves.
Expand All @@ -56,10 +56,10 @@ if_nightly! {
/// Attempt to resolve the future to a final value, registering the current task
/// for wakeup if the value is not yet available.
///
/// This method takes `self` by `Pin`, and so calling it requires putting `Self`
/// This method takes `self` by `PinMut`, and so calling it requires putting `Self`
/// in a [`PinBox`](::std::boxed::PinBox) using the `pin` method, or otherwise
/// guaranteeing that the location of `self` will not change after a call to `poll`.
fn poll(self: Pin<Self>, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error>;
fn poll(self: PinMut<Self>, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error>;

/// Pin the future to a particular location by placing it on the heap.
#[cfg(feature = "std")]
Expand All @@ -85,14 +85,14 @@ if_nightly! {
type Item = F::Item;
type Error = F::Error;

fn poll(mut self: Pin<Self>, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
F::poll(unsafe { Pin::get_mut(&mut self) }, ctx)
fn poll(self: PinMut<Self>, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
F::poll(unsafe { PinMut::get_mut(self) }, ctx)
}
}

/// A trait for `Stream`s which can be pinned to a particular location in memory.
///
/// These streams take `self` by `Pin<Self>`, rather than `&mut Self`.
/// These streams take `self` by `PinMut<Self>`, rather than `&mut Self`.
/// This allows types which are not [`Unpin`](::std::marker::Unpin) to guarantee
/// that they won't be moved after being polled. Since they won't be moved, it's
/// possible for them to safely contain references to themselves.
Expand All @@ -110,10 +110,10 @@ if_nightly! {
/// Attempt to resolve the stream to the next value, registering the current task
/// for wakeup if the value is not yet available.
///
/// This method takes `self` by `Pin`, and so calling it requires putting `Self`
/// This method takes `self` by `PinMut`, and so calling it requires putting `Self`
/// in a [`PinBox`](::std::boxed::PinBox) using the `pin` method, or otherwise
/// guaranteeing that the location of `self` will not change after a call to `poll`.
fn poll_next(self: Pin<Self>, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error>;
fn poll_next(self: PinMut<Self>, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error>;

/// Pin the stream to a particular location by placing it on the heap.
#[cfg(feature = "std")]
Expand All @@ -139,8 +139,8 @@ if_nightly! {
type Item = S::Item;
type Error = S::Error;

fn poll_next(mut self: Pin<Self>, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
S::poll_next(unsafe { Pin::get_mut(&mut self) }, ctx)
fn poll_next(self: PinMut<Self>, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
S::poll_next(unsafe { PinMut::get_mut(self) }, ctx)
}
}
}
6 changes: 3 additions & 3 deletions futures-stable/src/unsafe_pin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::mem::Pin;
use core::mem::PinMut;
use futures_core::{Future, Stream, Poll, task};

use {StableFuture, StableStream};
Expand All @@ -17,14 +17,14 @@ impl<'a, T: StableFuture> Future for UnsafePin<T> {
type Item = T::Item;
type Error = T::Error;
fn poll(&mut self, ctx: &mut task::Context) -> Poll<Self::Item, Self::Error> {
T::poll(unsafe { Pin::new_unchecked(&mut self.inner) }, ctx)
T::poll(unsafe { PinMut::new_unchecked(&mut self.inner) }, ctx)
}
}

impl<'a, T: StableStream> Stream for UnsafePin<T> {
type Item = T::Item;
type Error = T::Error;
fn poll_next(&mut self, ctx: &mut task::Context) -> Poll<Option<Self::Item>, Self::Error> {
T::poll_next(unsafe { Pin::new_unchecked(&mut self.inner) }, ctx)
T::poll_next(unsafe { PinMut::new_unchecked(&mut self.inner) }, ctx)
}
}