diff --git a/tokio-sync/src/mpsc/bounded.rs b/tokio-sync/src/mpsc/bounded.rs index d7431731644..879d063c886 100644 --- a/tokio-sync/src/mpsc/bounded.rs +++ b/tokio-sync/src/mpsc/bounded.rs @@ -7,11 +7,17 @@ use std::fmt; /// Send values to the associated `Receiver`. /// /// Instances are created by the [`channel`](fn.channel.html) function. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct Sender { chan: chan::Tx, } +impl Clone for Sender { + fn clone(&self) -> Self { + Sender { chan: self.chan.clone() } + } +} + /// Receive values from the associated `Sender`. /// /// Instances are created by the [`channel`](fn.channel.html) function. diff --git a/tokio-sync/src/mpsc/unbounded.rs b/tokio-sync/src/mpsc/unbounded.rs index 957336517c9..16bb659e263 100644 --- a/tokio-sync/src/mpsc/unbounded.rs +++ b/tokio-sync/src/mpsc/unbounded.rs @@ -9,11 +9,17 @@ use std::fmt; /// /// Instances are created by the /// [`unbounded_channel`](fn.unbounded_channel.html) function. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct UnboundedSender { chan: chan::Tx, } +impl Clone for UnboundedSender { + fn clone(&self) -> Self { + UnboundedSender { chan: self.chan.clone() } + } +} + /// Receive values from the associated `UnboundedSender`. /// /// Instances are created by the diff --git a/tokio-sync/tests/mpsc.rs b/tokio-sync/tests/mpsc.rs index dca9b305b8c..4f2ea4f96e7 100644 --- a/tokio-sync/tests/mpsc.rs +++ b/tokio-sync/tests/mpsc.rs @@ -91,6 +91,36 @@ fn send_recv_unbounded() { assert!(val.is_none()); } +#[test] +fn clone_sender_no_t_clone_buffer() { + #[derive(Debug, PartialEq, Eq)] + struct NotClone; + let (mut tx, mut rx) = mpsc::channel(100); + tx.try_send(NotClone).unwrap(); + tx.clone().try_send(NotClone).unwrap(); + + let val = assert_ready!(rx.poll()); + assert_eq!(val, Some(NotClone)); + + let val = assert_ready!(rx.poll()); + assert_eq!(val, Some(NotClone)); +} + +#[test] +fn clone_sender_no_t_clone_unbounded() { + #[derive(Debug, PartialEq, Eq)] + struct NotClone; + let (mut tx, mut rx) = mpsc::unbounded_channel(); + tx.try_send(NotClone).unwrap(); + tx.clone().try_send(NotClone).unwrap(); + + let val = assert_ready!(rx.poll()); + assert_eq!(val, Some(NotClone)); + + let val = assert_ready!(rx.poll()); + assert_eq!(val, Some(NotClone)); +} + #[test] fn send_recv_buffer_limited() { let (mut tx, mut rx) = mpsc::channel::(1);