`tokio::select!` nested pattern matching with `rx.recv()` unexpected behavior

Hi, I use tokio::select! macro with broadcast::channel and I send through this channel AppEvent enum and got unexpected behavior for me:

#[tokio::main]
async fn main() {
    let (tx, mut rx) = broadcast::channel(100);
    
    tokio::spawn(async move {
        loop {
            let _ = sleep(Duration::from_secs(3));
            tx.send(AppEvent::Message("HelloTokio".to_string())).expect("failed to send");
        }
    });

    loop {
        select! {
            // This branch not executed and we get SendError panic
            Ok(AppEvent::Message(msg)) = rx.recv() => {
                println!("got message: {}", msg);
            }
            // BUT this work correctly and receive events
            // Ok(e) = rx.recv() => {
            //    println!("got event: {:?}", e);
            // }
            else => {
                println!("exit");
                break;
            },
        }
    }
}

#[derive(Debug, Clone)]
enum AppEvent {
    Message(String),
}

All works great when we use pattern match in tokio::select! like Ok(event) = rx.recv() => {} but if we add nested resolve of enum value, like this Ok(AppEvent::Message(text)) = rx.recv() => {} then rx seems not recognize it and if we try tx.send(AppEvent::Message("Hello".to_string())).expect("fail") we got panic SendError.

Example:

Can you explain to me what the reason is? And is everything working as epected?

I ran your code and saw lots of got message and a panic. The obvious bug is that you are not awaiting the sleep, so no actual sleep happens; this quickly fills up the channel and leads to the panic.