From 145197de239753d9f243a6640c00368e6c429dc0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 28 Feb 2024 12:13:56 -0800 Subject: [PATCH 1/2] Add test of select's grammar --- futures/tests/async_await_macros.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/futures/tests/async_await_macros.rs b/futures/tests/async_await_macros.rs index e87a5bf05..dbddf686a 100644 --- a/futures/tests/async_await_macros.rs +++ b/futures/tests/async_await_macros.rs @@ -57,6 +57,18 @@ fn select() { assert!(ran); } +#[test] +fn select_grammar() { + // Parsing after `=>` using Expr::parse would parse `{}() = future::ready(())` + // as one expression. + block_on(async { + select! { + () = future::pending::<()>() => {} + () = future::ready(()) => {} + } + }); +} + #[test] fn select_biased() { let (tx1, rx1) = oneshot::channel::(); From 52fb316c22f4dbd2b33f84823b19eb9b2bf65648 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 28 Feb 2024 12:07:45 -0800 Subject: [PATCH 2/2] Parse rhs of `select!` arms using match-arm rules --- futures-macro/Cargo.toml | 2 +- futures-macro/src/select.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/futures-macro/Cargo.toml b/futures-macro/Cargo.toml index ddd740aa7..c6fe91cd1 100644 --- a/futures-macro/Cargo.toml +++ b/futures-macro/Cargo.toml @@ -18,7 +18,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0.60" quote = "1.0" -syn = { version = "2.0.8", features = ["full"] } +syn = { version = "2.0.52", features = ["full"] } [lints] workspace = true diff --git a/futures-macro/src/select.rs b/futures-macro/src/select.rs index 4cd8c7bc6..57bb74a84 100644 --- a/futures-macro/src/select.rs +++ b/futures-macro/src/select.rs @@ -59,7 +59,7 @@ impl Parse for Select { // `=> ` input.parse::]>()?; - let expr = input.parse::()?; + let expr = Expr::parse_with_earlier_boundary_rule(input)?; // Commas after the expression are only optional if it's a `Block` // or it is the last branch in the `match`. @@ -229,7 +229,7 @@ fn select_inner(input: TokenStream, random: bool) -> TokenStream { let branches = parsed.normal_fut_handlers.into_iter().zip(variant_names.iter()).map( |((pat, expr), variant_name)| { quote! { - #enum_ident::#variant_name(#pat) => { #expr }, + #enum_ident::#variant_name(#pat) => #expr, } }, );