diff --git a/.travis.yml b/.travis.yml index 01b739ff7..54d234923 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,7 @@ matrix: script: | cd tokio-async-await cargo check --all + cargo check --features async-await-preview # This runs TSAN against nightly and allows failures to propagate up. - rust: nightly-2018-11-18 diff --git a/tokio-async-await/README.md b/tokio-async-await/README.md index 3ed1f2a14..f76746165 100644 --- a/tokio-async-await/README.md +++ b/tokio-async-await/README.md @@ -9,7 +9,7 @@ guarantees. You are living on the edge here.** ## Usage To use this crate, you need to start with a Rust 2018 edition crate, with rustc -1.33.0-nightly or later. +1.34.0-nightly or later. Add this to your `Cargo.toml`: diff --git a/tokio-async-await/src/compat/backward.rs b/tokio-async-await/src/compat/backward.rs index fca801821..c84969bff 100644 --- a/tokio-async-await/src/compat/backward.rs +++ b/tokio-async-await/src/compat/backward.rs @@ -2,8 +2,8 @@ use futures::{Future, Poll}; use std::future::Future as StdFuture; use std::pin::Pin; -use std::ptr::NonNull; -use std::task::{LocalWaker, Poll as StdPoll, UnsafeWake, Waker}; +use std::ptr; +use std::task::{Poll as StdPoll, RawWaker, RawWakerVTable, Waker}; /// Convert an 0.3 `Future` to an 0.1 `Future`. #[derive(Debug)] @@ -44,9 +44,9 @@ where fn poll(&mut self) -> Poll { use futures::Async::*; - let local_waker = noop_local_waker(); + let waker = noop_waker(); - let res = self.0.as_mut().poll(&local_waker); + let res = self.0.as_mut().poll(&waker); match res { StdPoll::Ready(Ok(val)) => Ok(Ready(val)), @@ -58,26 +58,26 @@ where // ===== NoopWaker ===== -struct NoopWaker; - -fn noop_local_waker() -> LocalWaker { - let w: NonNull = NonNull::dangling(); - unsafe { LocalWaker::new(w) } +fn noop_raw_waker() -> RawWaker { + RawWaker::new(ptr::null(), &NOOP_WAKER_VTABLE) } fn noop_waker() -> Waker { - let w: NonNull = NonNull::dangling(); - unsafe { Waker::new(w) } + unsafe { Waker::new_unchecked(noop_raw_waker()) } } -unsafe impl UnsafeWake for NoopWaker { - unsafe fn clone_raw(&self) -> Waker { - noop_waker() - } - - unsafe fn drop_raw(&self) {} - - unsafe fn wake(&self) { - unimplemented!("async-await-preview currently only supports futures 0.1. Use the compatibility layer of futures 0.3 instead, if you want to use futures 0.3."); - } +unsafe fn clone_raw(_data: *const ()) -> RawWaker { + noop_raw_waker() } + +unsafe fn drop_raw(_data: *const ()) {} + +unsafe fn wake(_data: *const ()) { + unimplemented!("async-await-preview currently only supports futures 0.1. Use the compatibility layer of futures 0.3 instead, if you want to use futures 0.3."); +} + +const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable { + clone: clone_raw, + drop: drop_raw, + wake, +}; diff --git a/tokio-async-await/src/compat/forward.rs b/tokio-async-await/src/compat/forward.rs index bd99ed236..1a629db66 100644 --- a/tokio-async-await/src/compat/forward.rs +++ b/tokio-async-await/src/compat/forward.rs @@ -1,9 +1,8 @@ use futures::{Async, Future}; use std::future::Future as StdFuture; -use std::marker::Unpin; use std::pin::Pin; -use std::task::{LocalWaker, Poll as StdPoll}; +use std::task::{Poll as StdPoll, Waker}; /// Converts an 0.1 `Future` into an 0.3 `Future`. #[derive(Debug)] @@ -54,7 +53,7 @@ where { type Output = Result; - fn poll(mut self: Pin<&mut Self>, _lw: &LocalWaker) -> StdPoll { + fn poll(mut self: Pin<&mut Self>, _waker: &Waker) -> StdPoll { use futures::Async::{NotReady, Ready}; // TODO: wire in cx diff --git a/tokio-async-await/src/io/flush.rs b/tokio-async-await/src/io/flush.rs index 9443d152b..17d6b2d6f 100644 --- a/tokio-async-await/src/io/flush.rs +++ b/tokio-async-await/src/io/flush.rs @@ -2,9 +2,8 @@ use tokio_io::AsyncWrite; use std::future::Future; use std::io; -use std::marker::Unpin; use std::pin::Pin; -use std::task::{LocalWaker, Poll}; +use std::task::{Poll, Waker}; /// A future used to fully flush an I/O object. #[derive(Debug)] @@ -24,7 +23,7 @@ impl<'a, T: AsyncWrite + ?Sized> Flush<'a, T> { impl<'a, T: AsyncWrite + ?Sized> Future for Flush<'a, T> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, _wx: &LocalWaker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _wx: &Waker) -> Poll { use crate::compat::forward::convert_poll; convert_poll(self.writer.poll_flush()) } diff --git a/tokio-async-await/src/io/read.rs b/tokio-async-await/src/io/read.rs index 0886aef62..a54e91879 100644 --- a/tokio-async-await/src/io/read.rs +++ b/tokio-async-await/src/io/read.rs @@ -4,7 +4,6 @@ use std::future::Future; use std::task::{self, Poll}; use std::io; -use std::marker::Unpin; use std::pin::Pin; /// A future which can be used to read bytes. @@ -26,7 +25,7 @@ impl<'a, T: AsyncRead + ?Sized> Read<'a, T> { impl<'a, T: AsyncRead + ?Sized> Future for Read<'a, T> { type Output = io::Result; - fn poll(mut self: Pin<&mut Self>, _lw: &task::LocalWaker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/io/read_exact.rs b/tokio-async-await/src/io/read_exact.rs index 7b1ec1e9b..f0f84c16a 100644 --- a/tokio-async-await/src/io/read_exact.rs +++ b/tokio-async-await/src/io/read_exact.rs @@ -4,7 +4,6 @@ use std::future::Future; use std::task::{self, Poll}; use std::io; -use std::marker::Unpin; use std::mem; use std::pin::Pin; @@ -31,7 +30,7 @@ fn eof() -> io::Error { impl<'a, T: AsyncRead + ?Sized> Future for ReadExact<'a, T> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, _lw: &task::LocalWaker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/io/write.rs b/tokio-async-await/src/io/write.rs index af6f7adfa..93ffdd71b 100644 --- a/tokio-async-await/src/io/write.rs +++ b/tokio-async-await/src/io/write.rs @@ -4,7 +4,6 @@ use std::future::Future; use std::task::{self, Poll}; use std::io; -use std::marker::Unpin; use std::pin::Pin; /// A future used to write data. @@ -26,7 +25,7 @@ impl<'a, T: AsyncWrite + ?Sized> Write<'a, T> { impl<'a, T: AsyncWrite + ?Sized> Future for Write<'a, T> { type Output = io::Result; - fn poll(mut self: Pin<&mut Self>, _lw: &task::LocalWaker) -> Poll> { + fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll> { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/io/write_all.rs b/tokio-async-await/src/io/write_all.rs index fcc72b567..6b7963c15 100644 --- a/tokio-async-await/src/io/write_all.rs +++ b/tokio-async-await/src/io/write_all.rs @@ -4,7 +4,6 @@ use std::future::Future; use std::task::{self, Poll}; use std::io; -use std::marker::Unpin; use std::mem; use std::pin::Pin; @@ -31,7 +30,7 @@ fn zero_write() -> io::Error { impl<'a, T: AsyncWrite + ?Sized> Future for WriteAll<'a, T> { type Output = io::Result<()>; - fn poll(mut self: Pin<&mut Self>, _lw: &task::LocalWaker) -> Poll> { + fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll> { use crate::compat::forward::convert_poll; let this = &mut *self; diff --git a/tokio-async-await/src/lib.rs b/tokio-async-await/src/lib.rs index 38a335c64..388da6149 100644 --- a/tokio-async-await/src/lib.rs +++ b/tokio-async-await/src/lib.rs @@ -1,11 +1,5 @@ #![cfg(feature = "async-await-preview")] -#![feature( - rust_2018_preview, - arbitrary_self_types, - async_await, - await_macro, - futures_api -)] +#![feature(rust_2018_preview, async_await, await_macro, futures_api)] #![doc(html_root_url = "https://docs.rs/tokio-async-await/0.1.5")] #![deny(missing_docs, missing_debug_implementations)] #![cfg_attr(test, deny(warnings))] diff --git a/tokio-async-await/src/sink/mod.rs b/tokio-async-await/src/sink/mod.rs index 69c3f079e..4edc0517b 100644 --- a/tokio-async-await/src/sink/mod.rs +++ b/tokio-async-await/src/sink/mod.rs @@ -6,8 +6,6 @@ pub use self::send::Send; use futures::Sink; -use std::marker::Unpin; - /// An extension trait which adds utility methods to `Sink` types. pub trait SinkExt: Sink { /// Send an item into the sink. diff --git a/tokio-async-await/src/sink/send.rs b/tokio-async-await/src/sink/send.rs index b86f1a54b..c33948a45 100644 --- a/tokio-async-await/src/sink/send.rs +++ b/tokio-async-await/src/sink/send.rs @@ -3,7 +3,6 @@ use futures::Sink; use std::future::Future; use std::task::{self, Poll}; -use std::marker::Unpin; use std::pin::Pin; /// Future for the `SinkExt::send_async` combinator, which sends a value to a @@ -28,7 +27,7 @@ impl<'a, T: Sink + Unpin + ?Sized> Send<'a, T> { impl Future for Send<'_, T> { type Output = Result<(), T::SinkError>; - fn poll(mut self: Pin<&mut Self>, _lw: &task::LocalWaker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _waker: &task::Waker) -> Poll { use crate::compat::forward::convert_poll; use futures::AsyncSink::{NotReady, Ready}; diff --git a/tokio-async-await/src/stream/mod.rs b/tokio-async-await/src/stream/mod.rs index b376f49c2..a5a0c2d2f 100644 --- a/tokio-async-await/src/stream/mod.rs +++ b/tokio-async-await/src/stream/mod.rs @@ -6,8 +6,6 @@ pub use self::next::Next; use futures::Stream; -use std::marker::Unpin; - /// An extension trait which adds utility methods to `Stream` types. pub trait StreamExt: Stream { /// Creates a future that resolves to the next item in the stream. diff --git a/tokio-async-await/src/stream/next.rs b/tokio-async-await/src/stream/next.rs index 1ca245372..69197188a 100644 --- a/tokio-async-await/src/stream/next.rs +++ b/tokio-async-await/src/stream/next.rs @@ -1,9 +1,8 @@ use futures::Stream; use std::future::Future; -use std::marker::Unpin; use std::pin::Pin; -use std::task::{LocalWaker, Poll}; +use std::task::{Poll, Waker}; /// A future of the next element of a stream. #[derive(Debug)] @@ -22,7 +21,7 @@ impl<'a, T: Stream + Unpin> Next<'a, T> { impl<'a, T: Stream + Unpin> Future for Next<'a, T> { type Output = Option>; - fn poll(mut self: Pin<&mut Self>, _lw: &LocalWaker) -> Poll { + fn poll(mut self: Pin<&mut Self>, _waker: &Waker) -> Poll { use crate::compat::forward::convert_poll_stream; convert_poll_stream(self.stream.poll())