Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/futures-rs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b3d00ede0efd75e16c82de5421465b630918ea9d
Choose a base ref
..
head repository: rust-lang/futures-rs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6dedd3b60215701ffd2fdcff2409bcdb218adc33
Choose a head ref
Showing with 424 additions and 264 deletions.
  1. +1 −1 .travis.yml
  2. +1 −1 README.md
  3. +1 −1 futures-async-macro/README.md
  4. +21 −20 futures-async-macro/src/lib.rs
  5. +2 −2 futures-channel/tests/channel.rs
  6. +3 −3 futures-channel/tests/mpsc.rs
  7. +1 −1 futures-select-macro/src/lib.rs
  8. +8 −8 futures-util/src/async_await/join.rs
  9. +1 −1 futures-util/src/async_await/pending.rs
  10. +1 −1 futures-util/src/async_await/poll.rs
  11. +3 −3 futures-util/src/async_await/select_mod.rs
  12. +13 −13 futures-util/src/compat/compat01as03.rs
  13. +1 −1 futures-util/src/compat/executor.rs
  14. +2 −2 futures-util/src/future/empty.rs
  15. +1 −1 futures-util/src/future/fuse.rs
  16. +8 −8 futures-util/src/future/join.rs
  17. +2 −2 futures-util/src/future/join_all.rs
  18. +2 −2 futures-util/src/future/lazy.rs
  19. +2 −2 futures-util/src/future/maybe_done.rs
  20. +22 −22 futures-util/src/future/mod.rs
  21. +3 −3 futures-util/src/future/option.rs
  22. +2 −2 futures-util/src/future/poll_fn.rs
  23. +6 −6 futures-util/src/future/ready.rs
  24. +49 −0 futures-util/src/io/lines.rs
  25. +69 −30 futures-util/src/io/mod.rs
  26. +22 −10 futures-util/src/io/read_line.rs
  27. +1 −1 futures-util/src/io/read_until.rs
  28. +1 −1 futures-util/src/lib.rs
  29. +2 −2 futures-util/src/sink/drain.rs
  30. +0 −4 futures-util/src/sink/map_err.rs
  31. +13 −13 futures-util/src/stream/mod.rs
  32. +4 −4 futures-util/src/task/spawn.rs
  33. +19 −19 futures-util/src/try_future/mod.rs
  34. +10 −10 futures-util/src/try_future/try_join.rs
  35. +3 −3 futures-util/src/try_future/try_join_all.rs
  36. +0 −1 futures-util/src/try_stream/map_err.rs
  37. +0 −1 futures-util/src/try_stream/map_ok.rs
  38. +40 −40 futures-util/src/try_stream/mod.rs
  39. +1 −1 futures-util/tests/futures_unordered.rs
  40. +5 −5 futures-util/tests/mutex.rs
  41. +1 −1 futures-util/tests/select_all.rs
  42. +1 −1 futures-util/tests/select_next_some.rs
  43. +1 −0 futures/src/lib.rs
  44. +1 −1 futures/testcrate/ui/nested.rs
  45. +5 −5 futures/tests/async_await_macros.rs
  46. +2 −2 futures/tests/async_stream/nested.rs
  47. +1 −1 futures/tests/async_stream_tests.rs
  48. +2 −2 futures/tests/compat.rs
  49. +64 −0 futures/tests/io_lines.rs
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ matrix:

# When updating this, the reminder to update the minimum required version in README.md.
- name: cargo test (minimum required version)
rust: nightly-2019-04-30
rust: nightly-2019-05-09

- name: cargo clippy
rust: nightly
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ Now, you can use futures-rs:
use futures::future::Future; // Note: It's not `futures_preview`
```

The current version of futures-rs requires Rust nightly 2019-04-30 or later.
The current version of futures-rs requires Rust nightly 2019-05-09 or later.

### Feature `std`

2 changes: 1 addition & 1 deletion futures-async-macro/README.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ Processes streams using a for loop.
This is a reimplement of [futures-await]'s `#[async]` for loops for futures 0.3 and is an experimental implementation of [the idea listed as the next step of async/await](https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#for-await-and-processing-streams).

```rust
#![feature(async_await, await_macro, stmt_expr_attributes, proc_macro_hygiene)]
#![feature(async_await, stmt_expr_attributes, proc_macro_hygiene)]
use futures::for_await;
use futures::prelude::*;

41 changes: 21 additions & 20 deletions futures-async-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ use proc_macro2::{Span, TokenStream as TokenStream2, TokenTree as TokenTree2};
use quote::{quote, ToTokens};
use syn::{
fold::{self, Fold},
token, ArgCaptured, Error, Expr, ExprCall, ExprForLoop, ExprMacro, ExprYield, FnArg, FnDecl,
Ident, Item, ItemFn, Pat, PatIdent, ReturnType, TypeTuple,
token, ArgCaptured, Error, Expr, ExprCall, ExprField, ExprForLoop, ExprMacro, ExprYield, FnArg,
FnDecl, Ident, Item, ItemFn, Member, Pat, PatIdent, ReturnType, TypeTuple,
};

#[macro_use]
@@ -210,7 +210,7 @@ pub fn async_stream_block(input: TokenStream) -> TokenStream {
tokens.into()
}

/// The scope in which `#[for_await]`, `await!` was called.
/// The scope in which `#[for_await]`, `.await` was called.
///
/// The type of generator depends on which scope is called.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -221,7 +221,7 @@ enum Scope {
Stream,
/// `static move ||`, `||`
///
/// It cannot call `#[for_await]`, `await!` in this scope.
/// It cannot call `#[for_await]`, `.await` in this scope.
Closure,
}

@@ -256,7 +256,7 @@ impl Expand {
#label
loop {
let #pat = {
match r#await!(::futures::stream::StreamExt::next(&mut __pinned)) {
match ::futures::stream::StreamExt::next(&mut __pinned).await {
::futures::core_reexport::option::Option::Some(e) => e,
::futures::core_reexport::option::Option::None => break,
}
@@ -300,9 +300,7 @@ impl Expand {

/// Expands `yield expr` in `async_stream` scope.
fn expand_yield(&self, expr: ExprYield) -> ExprYield {
if self.0 != Stream {
return expr;
}
if self.0 != Stream { return expr }

let ExprYield { attrs, yield_token, expr } = expr;
let expr = expr.map_or_else(|| quote!(()), ToTokens::into_token_stream);
@@ -312,28 +310,30 @@ impl Expand {
ExprYield { attrs, yield_token, expr: Some(Box::new(expr)) }
}

/// Expands a macro.
/// Expands `async_stream_block!` macro.
fn expand_macro(&mut self, mut expr: ExprMacro) -> Expr {
if self.0 == Stream && expr.mac.path.is_ident("await") {
return self.expand_await_macros(expr);
} else if expr.mac.path.is_ident("async_stream_block") {
if expr.mac.path.is_ident("async_stream_block") {
let mut e: ExprCall = syn::parse(async_stream_block(expr.mac.tts.into())).unwrap();
e.attrs.append(&mut expr.attrs);
return Expr::Call(e);
Expr::Call(e)
} else {
Expr::Macro(expr)
}

Expr::Macro(expr)
}

/// Expands `await!(expr)` in `async_stream` scope.
/// Expands `expr.await` in `async_stream` scope.
///
/// It needs to adjust the type yielded by the macro because generators used internally by
/// async fn yield `()` type, but generators used internally by `async_stream` yield
/// `Poll<U>` type.
fn expand_await_macros(&mut self, expr: ExprMacro) -> Expr {
assert_eq!(self.0, Stream);
fn expand_await(&mut self, expr: ExprField) -> Expr {
if self.0 != Stream { return Expr::Field(expr) }

let expr = expr.mac.tts;
match &expr.member {
Member::Named(x) if x == "await" => {}
_ => return Expr::Field(expr),
}
let expr = expr.base;

// Because macro input (`#expr`) is untrusted, use `syn::parse2` + `expr_compile_error`
// instead of `syn::parse_quote!` to generate better error messages (`syn::parse_quote!`
@@ -368,8 +368,9 @@ impl Fold for Expand {
}

let expr = match fold::fold_expr(self, expr) {
Expr::ForLoop(expr) => self.expand_for_await(expr),
Expr::Yield(expr) => Expr::Yield(self.expand_yield(expr)),
Expr::Field(expr) => self.expand_await(expr),
Expr::ForLoop(expr) => self.expand_for_await(expr),
Expr::Macro(expr) => self.expand_macro(expr),
expr => expr,
};
4 changes: 2 additions & 2 deletions futures-channel/tests/channel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use futures::channel::mpsc;
use futures::executor::block_on;
@@ -28,7 +28,7 @@ fn sequence() {

async fn send_sequence(n: u32, mut sender: mpsc::Sender<u32>) {
for x in 0..n {
await!(sender.send(n - x)).unwrap();
sender.send(n - x).await.unwrap();
}
}

6 changes: 3 additions & 3 deletions futures-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use futures::channel::{mpsc, oneshot};
use futures::executor::{block_on, block_on_stream};
@@ -357,7 +357,7 @@ fn stress_drop_sender() {

async fn send_one_two_three(mut tx: mpsc::Sender<i32>) {
for i in 1..=3 {
await!(tx.send(i)).unwrap();
tx.send(i).await.unwrap();
}
}

@@ -403,7 +403,7 @@ fn stress_close_receiver() {

async fn stress_poll_ready_sender(mut sender: mpsc::Sender<u32>, count: u32) {
for i in (1..=count).rev() {
await!(sender.send(i)).unwrap();
sender.send(i).await.unwrap();
}
}

2 changes: 1 addition & 1 deletion futures-select-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ pub fn select(input: TokenStream) -> TokenStream {
}
} else {
quote! {
match r#await!(#futures_crate::future::poll_fn(__poll_fn)) {
match #futures_crate::future::poll_fn(__poll_fn).await {
#branches
}
}
16 changes: 8 additions & 8 deletions futures-util/src/async_await/join.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
/// Polls multiple futures simultaneously, returning a tuple
/// of all results once complete.
///
/// While `join!(a, b)` is similar to `(await!(a), await!(b))`,
/// While `join!(a, b)` is similar to `(a.await, b.await)`,
/// `join!` polls both futures concurrently and therefore is more efficent.
///
/// This macro is only usable inside of async functions, closures, and blocks.
@@ -13,7 +13,7 @@
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{join, future};
///
@@ -31,7 +31,7 @@ macro_rules! join {
// is no longer accessible by the end user.
let mut $fut = $crate::future::maybe_done($fut);
)*
await!($crate::future::poll_fn(move |cx| {
$crate::future::poll_fn(move |cx| {
let mut all_done = true;
$(
all_done &= $crate::core_reexport::future::Future::poll(
@@ -44,7 +44,7 @@ macro_rules! join {
} else {
$crate::core_reexport::task::Poll::Pending
}
}))
}).await
} }
}

@@ -64,7 +64,7 @@ macro_rules! join {
/// `Ok` of a tuple of the values:
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{try_join, future};
///
@@ -79,7 +79,7 @@ macro_rules! join {
/// that error:
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{try_join, future};
///
@@ -98,7 +98,7 @@ macro_rules! try_join {
let mut $fut = $crate::future::maybe_done($fut);
)*

let res: $crate::core_reexport::result::Result<_, _> = await!($crate::future::poll_fn(move |cx| {
let res: $crate::core_reexport::result::Result<_, _> = $crate::future::poll_fn(move |cx| {
let mut all_done = true;
$(
if $crate::core_reexport::future::Future::poll(
@@ -126,7 +126,7 @@ macro_rules! try_join {
} else {
$crate::core_reexport::task::Poll::Pending
}
}));
}).await;

res
} }
2 changes: 1 addition & 1 deletion futures-util/src/async_await/pending.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ use futures_core::task::{Context, Poll};
#[macro_export]
macro_rules! pending {
() => {
await!($crate::async_await::pending_once())
$crate::async_await::pending_once().await
}
}

2 changes: 1 addition & 1 deletion futures-util/src/async_await/poll.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ use futures_core::task::{Context, Poll};
#[macro_export]
macro_rules! poll {
($x:expr) => {
await!($crate::async_await::poll($x))
$crate::async_await::poll($x).await
}
}

6 changes: 3 additions & 3 deletions futures-util/src/async_await/select_mod.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ macro_rules! document_select_macro {
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future::{self, FutureExt};
/// use futures::select;
@@ -42,7 +42,7 @@ macro_rules! document_select_macro {
/// ```
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future::{self, FutureExt};
/// use futures::stream::{self, StreamExt};
@@ -64,7 +64,7 @@ macro_rules! document_select_macro {
/// the case where all futures have completed.
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future::{self, FutureExt};
/// use futures::select;
26 changes: 13 additions & 13 deletions futures-util/src/compat/compat01as03.rs
Original file line number Diff line number Diff line change
@@ -52,14 +52,14 @@ pub trait Future01CompatExt: Future01 {
/// [`Future<Output = Result<T, E>>`](futures_core::future::Future).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// # // TODO: These should be all using `futures::compat`, but that runs up against Cargo
/// # // feature issues
/// use futures_util::compat::Future01CompatExt;
///
/// let future = futures_01::future::ok::<u32, ()>(1);
/// assert_eq!(await!(future.compat()), Ok(1));
/// assert_eq!(future.compat().await, Ok(1));
/// # });
/// ```
fn compat(self) -> Compat01As03<Self>
@@ -79,15 +79,15 @@ pub trait Stream01CompatExt: Stream01 {
/// [`Stream<Item = Result<T, E>>`](futures_core::stream::Stream).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::stream::StreamExt;
/// use futures_util::compat::Stream01CompatExt;
///
/// let stream = futures_01::stream::once::<u32, ()>(Ok(1));
/// let mut stream = stream.compat();
/// assert_eq!(await!(stream.next()), Some(Ok(1)));
/// assert_eq!(await!(stream.next()), None);
/// assert_eq!(stream.next().await, Some(Ok(1)));
/// assert_eq!(stream.next().await, None);
/// # });
/// ```
fn compat(self) -> Compat01As03<Self>
@@ -107,18 +107,18 @@ pub trait Sink01CompatExt: Sink01 {
/// [`Sink<SinkItem = T, SinkError = E>`](futures_sink::sink::Sink).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{sink::SinkExt, stream::StreamExt};
/// use futures_util::compat::{Stream01CompatExt, Sink01CompatExt};
///
/// let (tx, rx) = futures_01::unsync::mpsc::channel(1);
/// let (mut tx, mut rx) = (tx.sink_compat(), rx.compat());
///
/// await!(tx.send(1)).unwrap();
/// tx.send(1).await.unwrap();
/// drop(tx);
/// assert_eq!(await!(rx.next()), Some(Ok(1)));
/// assert_eq!(await!(rx.next()), None);
/// assert_eq!(rx.next().await, Some(Ok(1)));
/// assert_eq!(rx.next().await, None);
/// # });
/// ```
fn sink_compat(self) -> Compat01As03Sink<Self, Self::SinkItem>
@@ -356,7 +356,7 @@ mod io {
/// [`AsyncRead`](futures_io::AsyncRead).
///
/// ```
/// #![feature(async_await, await_macro, impl_trait_in_bindings)]
/// #![feature(async_await, impl_trait_in_bindings)]
/// # futures::executor::block_on(async {
/// use futures::io::AsyncReadExt;
/// use futures_util::compat::AsyncRead01CompatExt;
@@ -366,7 +366,7 @@ mod io {
/// let mut reader: impl futures::io::AsyncRead + Unpin = reader.compat();
///
/// let mut output = Vec::with_capacity(12);
/// await!(reader.read_to_end(&mut output)).unwrap();
/// reader.read_to_end(&mut output).await.unwrap();
/// assert_eq!(output, input);
/// # });
/// ```
@@ -385,7 +385,7 @@ mod io {
/// [`AsyncWrite`](futures_io::AsyncWrite).
///
/// ```
/// #![feature(async_await, await_macro, impl_trait_in_bindings)]
/// #![feature(async_await, impl_trait_in_bindings)]
/// # futures::executor::block_on(async {
/// use futures::io::AsyncWriteExt;
/// use futures_util::compat::AsyncWrite01CompatExt;
@@ -394,7 +394,7 @@ mod io {
/// let mut cursor = std::io::Cursor::new(Vec::with_capacity(12));
///
/// let mut writer = (&mut cursor).compat();
/// await!(writer.write_all(input)).unwrap();
/// writer.write_all(input).await.unwrap();
///
/// assert_eq!(cursor.into_inner(), input);
/// # });
2 changes: 1 addition & 1 deletion futures-util/src/compat/executor.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ pub trait Executor01CompatExt: Executor01<Executor01Future> +
/// futures 0.3 [`Spawn`](futures_core::task::Spawn).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// use futures::Future;
/// use futures::task::SpawnExt;
/// use futures::future::{FutureExt, TryFutureExt};
Loading