macros: fix empty join! and try_join! (#5504)

Fixes: #5502
This commit is contained in:
Adrian Heine né Lang 2023-02-25 18:06:17 +01:00 committed by GitHub
parent c89406965f
commit ca9f7ee9f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View File

@ -158,7 +158,9 @@ macro_rules! join {
// ===== Entry point =====
( $($e:expr),* $(,)?) => {
( $($e:expr),+ $(,)?) => {
$crate::join!(@{ () (0) } $($e,)*)
};
() => { async {}.await }
}

View File

@ -210,7 +210,9 @@ macro_rules! try_join {
// ===== Entry point =====
( $($e:expr),* $(,)?) => {
( $($e:expr),+ $(,)?) => {
$crate::try_join!(@{ () (0) } $($e,)*)
};
() => { async { Ok(()) }.await }
}

View File

@ -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!(), ());
}

View File

@ -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(()));
}