From 0b8be261035c986b6fe4049ed22d533c2046f15d Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Sat, 25 Feb 2023 15:14:02 +0100 Subject: [PATCH] tokio: Fix empty `join!` and `try_join!` This closes #5502. --- tokio/src/macros/join.rs | 4 +++- tokio/src/macros/try_join.rs | 4 +++- tokio/tests/macros_join.rs | 5 +++++ tokio/tests/macros_try_join.rs | 5 +++++ 4 files changed, 16 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..1965906cd80 100644 --- a/tokio/tests/macros_join.rs +++ b/tokio/tests/macros_join.rs @@ -153,3 +153,8 @@ async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { *poll_order.lock().unwrap() ); } + +#[tokio::test] +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(())); +}