Skip to content

Commit 0e3fb18

Browse files
committed
std::sync::mpsc: Add fmt::Debug stubs
Minimal fix for #30563 This covers all the public structs I think; except for Iter and IntoIter, which I don't know if or how they should be handled.
1 parent e1f550e commit 0e3fb18

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/libstd/sync/mpsc/mod.rs

+39
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,13 @@ impl<T> Drop for Sender<T> {
635635
}
636636
}
637637

638+
#[stable(feature = "mpsc_debug", since = "1.7.0")]
639+
impl<T> fmt::Debug for Sender<T> {
640+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
641+
write!(f, "Sender {{ .. }}")
642+
}
643+
}
644+
638645
////////////////////////////////////////////////////////////////////////////////
639646
// SyncSender
640647
////////////////////////////////////////////////////////////////////////////////
@@ -693,6 +700,13 @@ impl<T> Drop for SyncSender<T> {
693700
}
694701
}
695702

703+
#[stable(feature = "mpsc_debug", since = "1.7.0")]
704+
impl<T> fmt::Debug for SyncSender<T> {
705+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
706+
write!(f, "SyncSender {{ .. }}")
707+
}
708+
}
709+
696710
////////////////////////////////////////////////////////////////////////////////
697711
// Receiver
698712
////////////////////////////////////////////////////////////////////////////////
@@ -987,6 +1001,13 @@ impl<T> Drop for Receiver<T> {
9871001
}
9881002
}
9891003

1004+
#[stable(feature = "mpsc_debug", since = "1.7.0")]
1005+
impl<T> fmt::Debug for Receiver<T> {
1006+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1007+
write!(f, "Receiver {{ .. }}")
1008+
}
1009+
}
1010+
9901011
#[stable(feature = "rust1", since = "1.0.0")]
9911012
impl<T> fmt::Debug for SendError<T> {
9921013
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -2199,4 +2220,22 @@ mod sync_tests {
21992220
repro()
22002221
}
22012222
}
2223+
2224+
#[test]
2225+
fn fmt_debug_sender() {
2226+
let (tx, _) = channel::<i32>();
2227+
assert_eq!(format!("{:?}", tx), "Sender { .. }");
2228+
}
2229+
2230+
#[test]
2231+
fn fmt_debug_recv() {
2232+
let (_, rx) = channel::<i32>();
2233+
assert_eq!(format!("{:?}", rx), "Receiver { .. }");
2234+
}
2235+
2236+
#[test]
2237+
fn fmt_debug_sync_sender() {
2238+
let (tx, _) = sync_channel::<i32>(1);
2239+
assert_eq!(format!("{:?}", tx), "SyncSender { .. }");
2240+
}
22022241
}

src/libstd/sync/mpsc/select.rs

+30
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
issue = "27800")]
5959

6060

61+
use fmt;
62+
6163
use core::cell::{Cell, UnsafeCell};
6264
use core::marker;
6365
use core::ptr;
@@ -350,6 +352,20 @@ impl Iterator for Packets {
350352
}
351353
}
352354

355+
#[stable(feature = "mpsc_debug", since = "1.7.0")]
356+
impl fmt::Debug for Select {
357+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
358+
write!(f, "Select {{ .. }}")
359+
}
360+
}
361+
362+
#[stable(feature = "mpsc_debug", since = "1.7.0")]
363+
impl<'rx, T:Send+'rx> fmt::Debug for Handle<'rx, T> {
364+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
365+
write!(f, "Handle {{ .. }}")
366+
}
367+
}
368+
353369
#[cfg(test)]
354370
#[allow(unused_imports)]
355371
mod tests {
@@ -762,4 +778,18 @@ mod tests {
762778
}
763779
}
764780
}
781+
782+
#[test]
783+
fn fmt_debug_select() {
784+
let sel = Select::new();
785+
assert_eq!(format!("{:?}", sel), "Select { .. }");
786+
}
787+
788+
#[test]
789+
fn fmt_debug_handle() {
790+
let (_, rx) = channel::<i32>();
791+
let sel = Select::new();
792+
let mut handle = sel.handle(&rx);
793+
assert_eq!(format!("{:?}", handle), "Handle { .. }");
794+
}
765795
}

0 commit comments

Comments
 (0)