Skip to content

Commit 2b82bdd

Browse files
committed
Remove await_item! macro
1 parent ca04b4f commit 2b82bdd

File tree

5 files changed

+7
-78
lines changed

5 files changed

+7
-78
lines changed

futures-async-macro/src/lib.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn async_stream_block(input: TokenStream) -> TokenStream {
207207
tokens.into()
208208
}
209209

210-
/// The scope in which `#[for_await]`, `await!` and `await_item!` was called.
210+
/// The scope in which `#[for_await]`, `await!` was called.
211211
///
212212
/// The type of generator depends on which scope is called.
213213
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -218,7 +218,7 @@ enum Scope {
218218
Stream,
219219
/// `static move ||`, `||`
220220
///
221-
/// It cannot call `#[for_await]`, `await!` and `await_item!` in this scope.
221+
/// It cannot call `#[for_await]`, `await!` in this scope.
222222
Closure,
223223
}
224224

@@ -297,13 +297,7 @@ impl Expand {
297297
/// Expands a macro.
298298
fn expand_macro(&mut self, mut expr: ExprMacro) -> Expr {
299299
if self.0 == Stream && expr.mac.path.is_ident("await") {
300-
return self.expand_await_macros(expr, "poll_with_tls_context");
301-
} else if expr.mac.path.is_ident("await_item") {
302-
match self.0 {
303-
Stream => return self.expand_await_macros(expr, "poll_next_with_tls_context"),
304-
Closure => return outside_of_async_error!(expr, "await_item!"),
305-
Future => {}
306-
}
300+
return self.expand_await_macros(expr);
307301
} else if expr.mac.path.is_ident("async_stream_block") {
308302
// FIXME: When added Parse impl for ExprCall, replace `if let ..` + `unreachable!()`
309303
// with `let` + `.unwrap()`
@@ -322,16 +316,15 @@ impl Expand {
322316
Expr::Macro(expr)
323317
}
324318

325-
/// Expands `await!(expr)` or `await_item!(expr)` in `async_stream` scope.
319+
/// Expands `await!(expr)` in `async_stream` scope.
326320
///
327321
/// It needs to adjust the type yielded by the macro because generators used internally by
328322
/// async fn yield `()` type, but generators used internally by `async_stream` yield
329323
/// `Poll<U>` type.
330-
fn expand_await_macros(&mut self, expr: ExprMacro, poll_fn: &str) -> Expr {
324+
fn expand_await_macros(&mut self, expr: ExprMacro) -> Expr {
331325
assert_eq!(self.0, Stream);
332326

333327
let expr = expr.mac.tts;
334-
let poll_fn = Ident::new(poll_fn, Span::call_site());
335328

336329
// Because macro input (`#expr`) is untrusted, use `syn::parse2` + `expr_compile_error`
337330
// instead of `syn::parse_quote!` to generate better error messages (`syn::parse_quote!`
@@ -340,7 +333,7 @@ impl Expand {
340333
let mut __pinned = #expr;
341334
loop {
342335
if let ::futures::core_reexport::task::Poll::Ready(x) =
343-
::futures::async_stream::#poll_fn(unsafe {
336+
::futures::async_stream::poll_with_tls_context(unsafe {
344337
::futures::core_reexport::pin::Pin::new_unchecked(&mut __pinned)
345338
})
346339
{

futures-util/src/async_stream/await_item.rs

-46
This file was deleted.

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 await_item;
8-
pub use self::await_item::*;
9-
106
#[macro_use]
117
mod stream_yield;
128
pub use self::stream_yield::*;

futures/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub use futures_util::{
7171
};
7272
// Async stream
7373
#[cfg(feature = "async-stream")]
74-
pub use futures_util::{await_item, stream_yield};
74+
pub use futures_util::stream_yield;
7575
#[cfg(feature = "async-stream")]
7676
#[doc(hidden)]
7777
pub use futures_util::async_stream;

futures/tests/async_stream/smoke.rs

-14
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,6 @@ async fn loop_in_loop() -> bool {
9595
cnt == sum
9696
}
9797

98-
fn await_item_stream() -> impl Stream<Item = u64> {
99-
stream::iter(vec![0, 1])
100-
}
101-
102-
async fn test_await_item() {
103-
let mut stream = await_item_stream();
104-
105-
assert_eq!(await_item!(&mut stream), Some(0));
106-
assert_eq!(await_item!(&mut stream), Some(1));
107-
assert_eq!(await_item!(&mut stream), None);
108-
assert_eq!(await_item!(&mut stream), None);
109-
}
110-
11198
#[test]
11299
fn main() {
113100
// https://github.com/alexcrichton/futures-await/issues/45
@@ -143,5 +130,4 @@ fn main() {
143130

144131
assert_eq!(block_on(future1()), 10);
145132
assert_eq!(block_on(loop_in_loop()), true);
146-
assert_eq!(block_on(test_await_item()), ());
147133
}

0 commit comments

Comments
 (0)