From ca9f7ee9f4750d6bb8a073ab4df1b7e4555857ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Heine=20n=C3=A9=20Lang?= Date: Sat, 25 Feb 2023 18:06:17 +0100 Subject: [PATCH] macros: fix empty `join!` and `try_join!` (#5504) Fixes: #5502 --- tokio/src/macros/join.rs | 4 +++- tokio/src/macros/try_join.rs | 4 +++- tokio/tests/macros_join.rs | 6 ++++++ tokio/tests/macros_try_join.rs | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tokio/src/macros/join.rs b/tokio/src/macros/join.rs index 7e85203c0..8a0198600 100644 --- a/tokio/src/macros/join.rs +++ b/tokio/src/macros/join.rs @@ -158,7 +158,9 @@ macro_rules! join { // ===== Entry point ===== - ( $($e:expr),* $(,)?) => { + ( $($e:expr),+ $(,)?) => { $crate::join!(@{ () (0) } $($e,)*) }; + + () => { async {}.await } } diff --git a/tokio/src/macros/try_join.rs b/tokio/src/macros/try_join.rs index 597cd5df0..7b1237092 100644 --- a/tokio/src/macros/try_join.rs +++ b/tokio/src/macros/try_join.rs @@ -210,7 +210,9 @@ macro_rules! try_join { // ===== Entry point ===== - ( $($e:expr),* $(,)?) => { + ( $($e:expr),+ $(,)?) => { $crate::try_join!(@{ () (0) } $($e,)*) }; + + () => { async { Ok(()) }.await } } diff --git a/tokio/tests/macros_join.rs b/tokio/tests/macros_join.rs index a87c6a6f8..7866ac086 100644 --- a/tokio/tests/macros_join.rs +++ b/tokio/tests/macros_join.rs @@ -153,3 +153,9 @@ async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { *poll_order.lock().unwrap() ); } + +#[tokio::test] +#[allow(clippy::unit_cmp)] +async fn empty_join() { + assert_eq!(tokio::join!(), ()); +} diff --git a/tokio/tests/macros_try_join.rs b/tokio/tests/macros_try_join.rs index 6c432221d..74b1c9f94 100644 --- a/tokio/tests/macros_try_join.rs +++ b/tokio/tests/macros_try_join.rs @@ -183,3 +183,8 @@ async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { *poll_order.lock().unwrap() ); } + +#[tokio::test] +async fn empty_try_join() { + assert_eq!(tokio::try_join!() as Result<_, ()>, Ok(())); +}