diff --git a/tokio/src/macros/select.rs b/tokio/src/macros/select.rs index 31c9b3ac2e5..8cf28405e7f 100644 --- a/tokio/src/macros/select.rs +++ b/tokio/src/macros/select.rs @@ -608,6 +608,10 @@ macro_rules! select { // ===== Entry point ===== + ($(biased;)? else => $else:expr $(,)? ) => {{ + $else + }}; + (biased; $p:pat = $($t:tt)* ) => { $crate::select!(@{ start=0; () } $p = $($t)*) }; @@ -617,6 +621,7 @@ macro_rules! select { // fair and avoids always polling the first future. $crate::select!(@{ start={ $crate::macros::support::thread_rng_n(BRANCHES) }; () } $p = $($t)*) }; + () => { compile_error!("select! requires at least one branch.") }; diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index 68a607b27f4..f65cbdf2267 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -22,6 +22,25 @@ async fn sync_one_lit_expr_comma() { assert_eq!(foo, 1); } +#[maybe_tokio_test] +async fn no_branch_else_only() { + let foo = tokio::select! { + else => 1, + }; + + assert_eq!(foo, 1); +} + +#[maybe_tokio_test] +async fn no_branch_else_only_biased() { + let foo = tokio::select! { + biased; + else => 1, + }; + + assert_eq!(foo, 1); +} + #[maybe_tokio_test] async fn nested_one() { let foo = tokio::select! {