mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
macros: allow select with only else branch (#6339)
This commit is contained in:
parent
84e41d4aff
commit
2ce1cee0f9
@ -608,6 +608,10 @@ macro_rules! select {
|
|||||||
|
|
||||||
// ===== Entry point =====
|
// ===== Entry point =====
|
||||||
|
|
||||||
|
($(biased;)? else => $else:expr $(,)? ) => {{
|
||||||
|
$else
|
||||||
|
}};
|
||||||
|
|
||||||
(biased; $p:pat = $($t:tt)* ) => {
|
(biased; $p:pat = $($t:tt)* ) => {
|
||||||
$crate::select!(@{ start=0; () } $p = $($t)*)
|
$crate::select!(@{ start=0; () } $p = $($t)*)
|
||||||
};
|
};
|
||||||
@ -617,6 +621,7 @@ macro_rules! select {
|
|||||||
// fair and avoids always polling the first future.
|
// fair and avoids always polling the first future.
|
||||||
$crate::select!(@{ start={ $crate::macros::support::thread_rng_n(BRANCHES) }; () } $p = $($t)*)
|
$crate::select!(@{ start={ $crate::macros::support::thread_rng_n(BRANCHES) }; () } $p = $($t)*)
|
||||||
};
|
};
|
||||||
|
|
||||||
() => {
|
() => {
|
||||||
compile_error!("select! requires at least one branch.")
|
compile_error!("select! requires at least one branch.")
|
||||||
};
|
};
|
||||||
|
@ -22,6 +22,25 @@ async fn sync_one_lit_expr_comma() {
|
|||||||
assert_eq!(foo, 1);
|
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]
|
#[maybe_tokio_test]
|
||||||
async fn nested_one() {
|
async fn nested_one() {
|
||||||
let foo = tokio::select! {
|
let foo = tokio::select! {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user