Skip to content

Commit c7288aa

Browse files
committed
Remove stream_yield! macro
1 parent 6745d01 commit c7288aa

20 files changed

+159
-213
lines changed

futures-async-macro/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ This is a reimplement of [futures-await]'s `#[async_stream]` for futures 0.3 and
3434

3535
```rust
3636
use futures::prelude::*;
37-
use futures::{async_stream, stream_yield};
37+
use futures::async_stream;
3838

3939
// Returns a stream of i32
4040
#[async_stream]
4141
fn foo(stream: impl Stream<Item = String>) -> i32 {
4242
#[for_await]
4343
for x in stream {
44-
stream_yield!(x.parse().unwrap());
44+
yield x.parse().unwrap();
4545
}
4646
}
4747
```
4848

49-
`#[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.
49+
`#[async_stream]` have an item type specified via `-> some::Path` and the values output from the stream must be yielded via the `yield` expression.
5050

5151
[futures-await]: https://github.com/alexcrichton/futures-await

futures-async-macro/src/lib.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use proc_macro2::{Span, TokenStream as TokenStream2, TokenTree as TokenTree2};
1010
use quote::{quote, ToTokens};
1111
use syn::{
1212
fold::{self, Fold},
13-
token, ArgCaptured, Error, Expr, ExprForLoop, ExprMacro, FnArg, FnDecl, Ident, Item, ItemFn,
14-
Pat, PatIdent, ReturnType, TypeTuple,
13+
token, ArgCaptured, Error, Expr, ExprForLoop, ExprMacro, ExprYield, FnArg, FnDecl, Ident, Item,
14+
ItemFn, Pat, PatIdent, ReturnType, TypeTuple,
1515
};
1616

1717
#[macro_use]
@@ -276,9 +276,6 @@ impl Expand {
276276
}}
277277
}
278278

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

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

316308
Expr::Macro(expr)
@@ -360,7 +352,7 @@ impl Fold for Expand {
360352

361353
let expr = match fold::fold_expr(self, expr) {
362354
Expr::ForLoop(expr) => self.expand_for_await(expr),
363-
// Expr::Yield(expr) => Expr::Yield(self.expand_yield(expr)),
355+
Expr::Yield(expr) => Expr::Yield(self.expand_yield(expr)),
364356
Expr::Macro(expr) => self.expand_macro(expr),
365357
expr => expr,
366358
};

futures-util/src/async_stream/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
//! This module contains a number of functions and combinators for working
44
//! with `async`/`await` code.
55
6-
#[macro_use]
7-
mod stream_yield;
8-
pub use self::stream_yield::*;
9-
106
use futures_core::future::Future;
117
use futures_core::stream::Stream;
128
use std::future::{self, get_task_context, set_task_context};

futures-util/src/async_stream/stream_yield.rs

-24
This file was deleted.

futures/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ pub use futures_util::{
6868
};
6969
// Async stream
7070
#[cfg(feature = "async-stream")]
71-
pub use futures_util::stream_yield;
72-
#[cfg(feature = "async-stream")]
7371
#[doc(hidden)]
7472
pub use futures_util::async_stream;
7573
#[cfg(feature = "async-stream")]

futures/testcrate/ui/bad-input-1.rs

-13
This file was deleted.

futures/testcrate/ui/bad-input-1.stderr

-8
This file was deleted.

futures/testcrate/ui/bad-input-2.rs renamed to futures/testcrate/ui/bad-input.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use futures::*;
77
fn foo() -> i32 {
88
#[for_await(bar)]
99
for i in stream::iter(vec![1, 2]) {
10-
stream_yield!(i);
10+
yield i;
1111
}
1212
}
1313

1414
#[async_stream(baz)]
1515
fn bar() -> i32 {
1616
#[for_await]
1717
for i in stream::iter(vec![1, 2]) {
18-
stream_yield!(i);
18+
yield i;
1919
}
2020
}
2121

futures/testcrate/ui/bad-input-2.stderr renamed to futures/testcrate/ui/bad-input.stderr

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

77
error: attribute must be of the form `#[async_stream]`
8-
--> $DIR/bad-input-2.rs:14:1
8+
--> $DIR/bad-input.rs:14:1
99
|
1010
14 | #[async_stream(baz)]
1111
| ^^^^^^^^^^^^^^^^^^^^

futures/testcrate/ui/bad-return-type.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ use futures::*;
66
fn foobar() -> Option<i32> {
77
let val = Some(42);
88
if val.is_none() {
9-
stream_yield!(None);
9+
yield None;
1010
return;
1111
}
1212
let val = val.unwrap();
13-
stream_yield!(val);
13+
yield val;
1414
}
1515

1616
#[async_stream]
1717
fn tuple() -> (i32, i32) {
1818
if false {
19-
stream_yield!(3);
19+
yield 3;
2020
}
21-
stream_yield!((1, 2))
21+
yield (1, 2)
2222
}
2323

2424
fn main() {}

0 commit comments

Comments
 (0)