From ce879f75257d89940e37fe8f8ed18459f0b6ae67 Mon Sep 17 00:00:00 2001 From: Gwo Tzu-Hsing Date: Thu, 11 Jan 2024 21:41:17 +0800 Subject: [PATCH] Ignore comma at the end of stream --- futures-async-stream-macro/src/parse.rs | 4 ++++ tests/stream.rs | 12 +++++++++++- tests/ui/threads-safety.stderr | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/futures-async-stream-macro/src/parse.rs b/futures-async-stream-macro/src/parse.rs index f4071a7..64cc01b 100644 --- a/futures-async-stream-macro/src/parse.rs +++ b/futures-async-stream-macro/src/parse.rs @@ -121,6 +121,10 @@ impl Parse for FnOrAsync { attrs.append(&mut expr.attrs); expr.attrs = attrs; + if input.peek(Token![,]) { + let _: Token![,] = input.parse()?; + } + Ok(Self::Async(expr, input.parse()?)) } else { input.parse::()?; // ignore all inputs diff --git a/tests/stream.rs b/tests/stream.rs index 032d74a..ce59db0 100644 --- a/tests/stream.rs +++ b/tests/stream.rs @@ -5,7 +5,8 @@ clippy::must_use_candidate, clippy::needless_lifetimes, clippy::no_effect_underscore_binding, - clippy::semicolon_if_nothing_returned + clippy::semicolon_if_nothing_returned, + clippy::unnecessary_wraps )] // broken #![feature(coroutines, proc_macro_hygiene, stmt_expr_attributes, gen_future)] @@ -180,6 +181,15 @@ pub async fn array() { yield [1, 2, 3, 4]; } +pub fn some_stream() -> Option { + Some( + #[stream] + async { + yield 1; + }, + ) +} + #[allow(clippy::toplevel_ref_arg)] pub mod arguments { use super::*; diff --git a/tests/ui/threads-safety.stderr b/tests/ui/threads-safety.stderr index 8adf4a6..79c3729 100644 --- a/tests/ui/threads-safety.stderr +++ b/tests/ui/threads-safety.stderr @@ -16,7 +16,7 @@ note: required because it appears within the type `Box>` note: required because it appears within the type `Pin>>` --> $RUST/core/src/pin.rs | - | pub struct Pin { + | pub struct Pin

{ | ^^^ note: required by a bound in `assert_send` --> tests/ui/threads-safety.rs:7:19