Skip to content

Commit 7b76d7d

Browse files
committed
macro select no branch, else fallback only
1 parent 84e41d4 commit 7b76d7d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tokio/src/macros/select.rs

+5
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ macro_rules! select {
608608

609609
// ===== Entry point =====
610610

611+
($(biased;)? else => $else:expr $(,)? ) => {{
612+
$else
613+
}};
614+
611615
(biased; $p:pat = $($t:tt)* ) => {
612616
$crate::select!(@{ start=0; () } $p = $($t)*)
613617
};
@@ -617,6 +621,7 @@ macro_rules! select {
617621
// fair and avoids always polling the first future.
618622
$crate::select!(@{ start={ $crate::macros::support::thread_rng_n(BRANCHES) }; () } $p = $($t)*)
619623
};
624+
620625
() => {
621626
compile_error!("select! requires at least one branch.")
622627
};

tokio/tests/macros_select.rs

+19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ async fn sync_one_lit_expr_comma() {
2222
assert_eq!(foo, 1);
2323
}
2424

25+
#[maybe_tokio_test]
26+
async fn no_branch_else_only() {
27+
let foo = tokio::select! {
28+
else => 1,
29+
};
30+
31+
assert_eq!(foo, 1);
32+
}
33+
34+
#[maybe_tokio_test]
35+
async fn no_branch_else_only_biased() {
36+
let foo = tokio::select! {
37+
biased;
38+
else => 1,
39+
};
40+
41+
assert_eq!(foo, 1);
42+
}
43+
2544
#[maybe_tokio_test]
2645
async fn nested_one() {
2746
let foo = tokio::select! {

0 commit comments

Comments
 (0)