Why does `tokio::select!` evaluate expressions for disabled branches?
⚓ Rust 📅 2025-10-08 👤 surdeus 👁️ 4It would be so convenient to be able to write code like this:
async fn f1() {
let t = Option::<u32>::None;
tokio::select! {
a = f(t.unwrap()), if t.is_some() => {
println!("{a}");
}
b = g(), if t.is_none() => {
println!("{b}");
}
}
}
But it'll panic because f(t.unwrap()) is evaluated even if t.is_none(). Is there a reason for this behavior?
5 posts - 3 participants
🏷️ Rust_feed