From e9d9ff3d0bb4ab57d480326b9adda422c6e8a6f3 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Sat, 25 Feb 2023 15:14:02 +0100 Subject: [PATCH] fix empty `join!` and `try_join!` 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 7e85203c0c4..8a0198600b2 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 597cd5df021..7b123709231 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 a87c6a6f86e..7866ac086fa 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 6c432221df1..74b1c9f9481 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(())); +}