diff --git a/tokio-sync/src/mpsc/bounded.rs b/tokio-sync/src/mpsc/bounded.rs index f2954448e37..9bbfe677014 100644 --- a/tokio-sync/src/mpsc/bounded.rs +++ b/tokio-sync/src/mpsc/bounded.rs @@ -111,6 +111,7 @@ pub struct RecvError(()); /// })); /// ``` pub fn channel(buffer: usize) -> (Sender, Receiver) { + assert_eq!(buffer >= 1, true); let semaphore = (::semaphore::Semaphore::new(buffer), buffer); let (tx, rx) = chan::channel(semaphore); diff --git a/tokio-sync/tests/mpsc.rs b/tokio-sync/tests/mpsc.rs index 5b184d4e248..b7ecd9efef9 100644 --- a/tokio-sync/tests/mpsc.rs +++ b/tokio-sync/tests/mpsc.rs @@ -65,6 +65,12 @@ fn send_recv_with_buffer() { assert!(val.is_none()); } +#[test] +#[should_panic] +fn buffer_gteq_one() { + mpsc::channel::(0); +} + #[test] fn send_recv_unbounded() { let (mut tx, mut rx) = mpsc::unbounded_channel::();