From 95b0eec8af9a7bbd6eaae35d0116b915ce34470e Mon Sep 17 00:00:00 2001 From: Stephen Carman Date: Fri, 1 Feb 2019 15:54:06 -0500 Subject: [PATCH] sync: bounded channel can not have 0 size (#879) --- tokio-sync/src/mpsc/bounded.rs | 1 + tokio-sync/tests/mpsc.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/tokio-sync/src/mpsc/bounded.rs b/tokio-sync/src/mpsc/bounded.rs index f2954448e..9bbfe6770 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 5b184d4e2..b7ecd9efe 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::();