Skip to content

Commit

Permalink
Remove stream_yield! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 25, 2019
1 parent 2970f56 commit daf904d
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 222 deletions.
6 changes: 3 additions & 3 deletions futures-async-macro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ This is a reimplement of [futures-await]'s `#[async_stream]` for futures 0.3 and

```rust
use futures::prelude::*;
use futures::{async_stream, stream_yield};
use futures::async_stream;

// Returns a stream of i32
#[async_stream]
fn foo(stream: impl Stream<Item = String>) -> i32 {
#[for_await]
for x in stream {
stream_yield!(x.parse().unwrap());
yield x.parse().unwrap();
}
}
```

`#[async_stream]` have an item type specified via `-> some::Path` and the values output from the stream must be yielded via the `stream_yield!` macro.
`#[async_stream]` have an item type specified via `-> some::Path` and the values output from the stream must be yielded via the `yield` expression.

[futures-await]: https://github.com/alexcrichton/futures-await
9 changes: 0 additions & 9 deletions futures-async-macro/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,3 @@ macro_rules! outside_of_async_error {
))
};
}

macro_rules! outside_of_async_stream_error {
($tokens:expr, $name:expr) => {
$crate::error::expr_compile_error(&syn::Error::new_spanned(
$tokens,
concat!($name, " cannot be allowed outside of async_stream blocks, and functions."),
))
};
}
14 changes: 3 additions & 11 deletions futures-async-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ExprForLoop, ExprMacro, FnArg, FnDecl, Ident, Item, ItemFn,
Pat, PatIdent, ReturnType, TypeTuple,
token, ArgCaptured, Error, Expr, ExprForLoop, ExprMacro, ExprYield, FnArg, FnDecl, Ident, Item,
ItemFn, Pat, PatIdent, ReturnType, TypeTuple,
};

#[macro_use]
Expand Down Expand Up @@ -276,9 +276,6 @@ impl Expand {
}}
}

/* TODO: If this is enabled, it can be used for `yield` instead of `stream_yield!`.
Raw `yield` is simpler, but it may be preferable to distinguish it from `yield` called
in other scopes.
/// Expands `yield expr` in `async_stream` scope.
fn expand_yield(&self, expr: ExprYield) -> ExprYield {
if self.0 != Stream {
Expand All @@ -292,7 +289,6 @@ impl Expand {
};
ExprYield { attrs, yield_token, expr: Some(Box::new(expr)) }
}
*/

/// Expands a macro.
fn expand_macro(&mut self, mut expr: ExprMacro) -> Expr {
Expand All @@ -307,10 +303,6 @@ impl Expand {
} else {
unreachable!()
}
} else if self.0 != Stream && expr.mac.path.is_ident("stream_yield") {
// TODO: Should we remove real `stream_yield!` macro and replace `stream_yield!` call in
// here? -- or should we use `yield` instead of ``?
return outside_of_async_stream_error!(expr, "stream_yield!");
}

Expr::Macro(expr)
Expand Down Expand Up @@ -360,7 +352,7 @@ 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::Yield(expr) => Expr::Yield(self.expand_yield(expr)),
Expr::Macro(expr) => self.expand_macro(expr),
expr => expr,
};
Expand Down
4 changes: 0 additions & 4 deletions futures-util/src/async_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
//! This module contains a number of functions and combinators for working
//! with `async`/`await` code.
#[macro_use]
mod stream_yield;
pub use self::stream_yield::*;

use futures_core::future::Future;
use futures_core::stream::Stream;
use std::future::{self, get_task_context, set_task_context};
Expand Down
24 changes: 0 additions & 24 deletions futures-util/src/async_stream/stream_yield.rs

This file was deleted.

2 changes: 0 additions & 2 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ pub use futures_util::{
};
// Async stream
#[cfg(feature = "async-stream")]
pub use futures_util::stream_yield;
#[cfg(feature = "async-stream")]
#[doc(hidden)]
pub use futures_util::async_stream;
#[cfg(feature = "async-stream")]
Expand Down
13 changes: 0 additions & 13 deletions futures/testcrate/ui/bad-input-1.rs

This file was deleted.

8 changes: 0 additions & 8 deletions futures/testcrate/ui/bad-input-1.stderr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use futures::*;
fn foo() -> i32 {
#[for_await(bar)]
for i in stream::iter(vec![1, 2]) {
stream_yield!(i);
yield i;
}
}

#[async_stream(baz)]
fn bar() -> i32 {
#[for_await]
for i in stream::iter(vec![1, 2]) {
stream_yield!(i);
yield i;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: attribute must be of the form `#[for_await]`
--> $DIR/bad-input-2.rs:8:5
--> $DIR/bad-input.rs:8:5
|
8 | #[for_await(bar)]
| ^^^^^^^^^^^^^^^^^

error: attribute must be of the form `#[async_stream]`
--> $DIR/bad-input-2.rs:14:1
--> $DIR/bad-input.rs:14:1
|
14 | #[async_stream(baz)]
| ^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions futures/testcrate/ui/bad-return-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ use futures::*;
fn foobar() -> Option<i32> {
let val = Some(42);
if val.is_none() {
stream_yield!(None);
yield None;
return;
}
let val = val.unwrap();
stream_yield!(val);
yield val;
}

#[async_stream]
fn tuple() -> (i32, i32) {
if false {
stream_yield!(3);
yield 3;
}
stream_yield!((1, 2))
yield (1, 2)
}

fn main() {}
Loading

0 comments on commit daf904d

Please sign in to comment.