From 8b181226061e53a083ee39e97aee7300302266a6 Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Tue, 29 Jan 2019 18:31:55 +0300 Subject: [PATCH] Fix breakage caused by nightly-2019-01-29 --- src/lib.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f4cbed6..23969c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,12 +39,13 @@ pub mod prelude { #[doc(hidden)] pub mod __rt { pub extern crate std; - pub use std::ops::Generator; - + use core::{ + marker::{PhantomData, Unpin}, + ops::{Generator, GeneratorState}, + pin::Pin, + }; use futures::Poll; use futures::{Async, Future, Stream}; - use std::marker::PhantomData; - use std::ops::GeneratorState; pub trait MyFuture: Future {} @@ -76,7 +77,7 @@ pub mod __rt { type Ok = T; type Err = E; - fn into_result(self) -> Result { + fn into_result(self) -> Result { self } } @@ -104,7 +105,7 @@ pub mod __rt { pub fn gen(gen: T) -> impl MyFuture where - T: Generator>, + T: Generator> + Unpin, T::Return: IsResult, { GenFuture(gen) @@ -112,7 +113,7 @@ pub mod __rt { pub fn gen_stream(gen: T) -> impl MyStream where - T: Generator>, + T: Generator> + Unpin, T::Return: IsResult, { GenStream { @@ -124,14 +125,14 @@ pub mod __rt { impl Future for GenFuture where - T: Generator>, + T: Generator> + Unpin, T::Return: IsResult, { type Item = ::Ok; type Error = ::Err; fn poll(&mut self) -> Poll { - match unsafe { self.0.resume() } { + match Pin::new(&mut self.0).resume() { GeneratorState::Yielded(Async::NotReady) => Ok(Async::NotReady), GeneratorState::Yielded(Async::Ready(mu)) => match mu {}, GeneratorState::Complete(e) => e.into_result().map(Async::Ready), @@ -141,7 +142,7 @@ pub mod __rt { impl Stream for GenStream where - T: Generator>, + T: Generator> + Unpin, T::Return: IsResult, { type Item = U; @@ -151,7 +152,7 @@ pub mod __rt { if self.done { return Ok(Async::Ready(None)); } - match unsafe { self.gen.resume() } { + match Pin::new(&mut self.gen).resume() { GeneratorState::Yielded(Async::Ready(e)) => Ok(Async::Ready(Some(e))), GeneratorState::Yielded(Async::NotReady) => Ok(Async::NotReady), GeneratorState::Complete(e) => {