diff --git a/futures-channel/src/mpsc/mod.rs b/futures-channel/src/mpsc/mod.rs index 44834b7c95..5d994bf8e7 100644 --- a/futures-channel/src/mpsc/mod.rs +++ b/futures-channel/src/mpsc/mod.rs @@ -94,13 +94,11 @@ mod queue; #[cfg(feature = "sink")] mod sink_impl; -#[derive(Debug)] struct UnboundedSenderInner { // Channel state shared between the sender and receiver. inner: Arc>, } -#[derive(Debug)] struct BoundedSenderInner { // Channel state shared between the sender and receiver. inner: Arc>, @@ -122,13 +120,11 @@ impl Unpin for BoundedSenderInner {} /// The transmission end of a bounded mpsc channel. /// /// This value is created by the [`channel`](channel) function. -#[derive(Debug)] pub struct Sender(Option>); /// The transmission end of an unbounded mpsc channel. /// /// This value is created by the [`unbounded`](unbounded) function. -#[derive(Debug)] pub struct UnboundedSender(Option>); trait AssertKinds: Send + Sync + Clone {} @@ -137,7 +133,6 @@ impl AssertKinds for UnboundedSender {} /// The receiving end of a bounded mpsc channel. /// /// This value is created by the [`channel`](channel) function. -#[derive(Debug)] pub struct Receiver { inner: Option>>, } @@ -145,7 +140,6 @@ pub struct Receiver { /// The receiving end of an unbounded mpsc channel. /// /// This value is created by the [`unbounded`](unbounded) function. -#[derive(Debug)] pub struct UnboundedReceiver { inner: Option>>, } @@ -261,7 +255,6 @@ impl fmt::Display for TryRecvError { impl std::error::Error for TryRecvError {} -#[derive(Debug)] struct UnboundedInner { // Internal channel state. Consists of the number of messages stored in the // channel as well as a flag signalling that the channel is closed. @@ -277,7 +270,6 @@ struct UnboundedInner { recv_task: AtomicWaker, } -#[derive(Debug)] struct BoundedInner { // Max buffer size of the channel. If `None` then the channel is unbounded. buffer: usize, @@ -300,7 +292,7 @@ struct BoundedInner { } // Struct representation of `Inner::state`. -#[derive(Debug, Clone, Copy)] +#[derive(Clone, Copy)] struct State { // `true` when the channel is open is_open: bool, @@ -324,7 +316,6 @@ const MAX_CAPACITY: usize = !(OPEN_MASK); const MAX_BUFFER: usize = MAX_CAPACITY >> 1; // Sent to the consumer to wake up blocked producers -#[derive(Debug)] struct SenderTask { task: Option, is_parked: bool, @@ -947,6 +938,18 @@ impl Drop for BoundedSenderInner { } } +impl fmt::Debug for Sender { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Sender").field("closed", &self.is_closed()).finish() + } +} + +impl fmt::Debug for UnboundedSender { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("UnboundedSender").field("closed", &self.is_closed()).finish() + } +} + /* * * ===== impl Receiver ===== @@ -1107,6 +1110,18 @@ impl Drop for Receiver { } } +impl fmt::Debug for Receiver { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let closed = if let Some(ref inner) = self.inner { + decode_state(inner.state.load(SeqCst)).is_closed() + } else { + false + }; + + f.debug_struct("Receiver").field("closed", &closed).finish() + } +} + impl UnboundedReceiver { /// Closes the receiving half of a channel, without dropping it. /// @@ -1239,6 +1254,18 @@ impl Drop for UnboundedReceiver { } } +impl fmt::Debug for UnboundedReceiver { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let closed = if let Some(ref inner) = self.inner { + decode_state(inner.state.load(SeqCst)).is_closed() + } else { + false + }; + + f.debug_struct("Receiver").field("closed", &closed).finish() + } +} + /* * * ===== impl Inner ===== diff --git a/futures-channel/src/mpsc/queue.rs b/futures-channel/src/mpsc/queue.rs index 57dc7f5654..02ec633fe0 100644 --- a/futures-channel/src/mpsc/queue.rs +++ b/futures-channel/src/mpsc/queue.rs @@ -61,7 +61,6 @@ pub(super) enum PopResult { Inconsistent, } -#[derive(Debug)] struct Node { next: AtomicPtr, value: Option, @@ -70,7 +69,6 @@ struct Node { /// The multi-producer single-consumer structure. This is not cloneable, but it /// may be safely shared so long as it is guaranteed that there is only one /// popper at a time (many pushers are allowed). -#[derive(Debug)] pub(super) struct Queue { head: AtomicPtr>, tail: UnsafeCell<*mut Node>,