Rollup merge of #44775 - MaloJaffre:debug-struct, r=sfackler
Refactor to use `debug_struct` in several Debug impls Also use `pad` and derive `Debug` for `Edge`. Fixes #44771.
This commit is contained in:
commit
23a99f4e0e
@ -31,7 +31,7 @@
|
||||
//! be indexed by the direction (see the type `Direction`).
|
||||
|
||||
use bitvec::BitVector;
|
||||
use std::fmt::{Formatter, Error, Debug};
|
||||
use std::fmt::Debug;
|
||||
use std::usize;
|
||||
use snapshot_vec::{SnapshotVec, SnapshotVecDelegate};
|
||||
|
||||
@ -48,6 +48,7 @@ pub struct Node<N> {
|
||||
pub data: N,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Edge<E> {
|
||||
next_edge: [EdgeIndex; 2], // see module comment
|
||||
source: NodeIndex,
|
||||
@ -69,18 +70,6 @@ impl<N> SnapshotVecDelegate for Edge<N> {
|
||||
fn reverse(_: &mut Vec<Edge<N>>, _: ()) {}
|
||||
}
|
||||
|
||||
impl<E: Debug> Debug for Edge<E> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
write!(f,
|
||||
"Edge {{ next_edge: [{:?}, {:?}], source: {:?}, target: {:?}, data: {:?} }}",
|
||||
self.next_edge[0],
|
||||
self.next_edge[1],
|
||||
self.source,
|
||||
self.target,
|
||||
self.data)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub struct NodeIndex(pub usize);
|
||||
|
||||
|
@ -919,7 +919,7 @@ impl<T> Drop for Sender<T> {
|
||||
#[stable(feature = "mpsc_debug", since = "1.8.0")]
|
||||
impl<T> fmt::Debug for Sender<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Sender {{ .. }}")
|
||||
f.debug_struct("Sender").finish()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1049,7 +1049,7 @@ impl<T> Drop for SyncSender<T> {
|
||||
#[stable(feature = "mpsc_debug", since = "1.8.0")]
|
||||
impl<T> fmt::Debug for SyncSender<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "SyncSender {{ .. }}")
|
||||
f.debug_struct("SyncSender").finish()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1551,7 +1551,7 @@ impl<T> Drop for Receiver<T> {
|
||||
#[stable(feature = "mpsc_debug", since = "1.8.0")]
|
||||
impl<T> fmt::Debug for Receiver<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Receiver {{ .. }}")
|
||||
f.debug_struct("Receiver").finish()
|
||||
}
|
||||
}
|
||||
|
||||
@ -3009,22 +3009,4 @@ mod sync_tests {
|
||||
repro()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_debug_sender() {
|
||||
let (tx, _) = channel::<i32>();
|
||||
assert_eq!(format!("{:?}", tx), "Sender { .. }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_debug_recv() {
|
||||
let (_, rx) = channel::<i32>();
|
||||
assert_eq!(format!("{:?}", rx), "Receiver { .. }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_debug_sync_sender() {
|
||||
let (tx, _) = sync_channel::<i32>(1);
|
||||
assert_eq!(format!("{:?}", tx), "SyncSender { .. }");
|
||||
}
|
||||
}
|
||||
|
@ -354,13 +354,13 @@ impl Iterator for Packets {
|
||||
|
||||
impl fmt::Debug for Select {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Select {{ .. }}")
|
||||
f.debug_struct("Select").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rx, T:Send+'rx> fmt::Debug for Handle<'rx, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Handle {{ .. }}")
|
||||
f.debug_struct("Handle").finish()
|
||||
}
|
||||
}
|
||||
|
||||
@ -774,18 +774,4 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_debug_select() {
|
||||
let sel = Select::new();
|
||||
assert_eq!(format!("{:?}", sel), "Select { .. }");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fmt_debug_handle() {
|
||||
let (_, rx) = channel::<i32>();
|
||||
let sel = Select::new();
|
||||
let handle = sel.handle(&rx);
|
||||
assert_eq!(format!("{:?}", handle), "Handle { .. }");
|
||||
}
|
||||
}
|
||||
|
@ -394,11 +394,18 @@ impl<T: ?Sized + Default> Default for Mutex<T> {
|
||||
impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.try_lock() {
|
||||
Ok(guard) => write!(f, "Mutex {{ data: {:?} }}", &*guard),
|
||||
Ok(guard) => f.debug_struct("Mutex").field("data", &&*guard).finish(),
|
||||
Err(TryLockError::Poisoned(err)) => {
|
||||
write!(f, "Mutex {{ data: Poisoned({:?}) }}", &**err.get_ref())
|
||||
f.debug_struct("Mutex").field("data", &&**err.get_ref()).finish()
|
||||
},
|
||||
Err(TryLockError::WouldBlock) => write!(f, "Mutex {{ <locked> }}")
|
||||
Err(TryLockError::WouldBlock) => {
|
||||
struct LockedPlaceholder;
|
||||
impl fmt::Debug for LockedPlaceholder {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("<locked>") }
|
||||
}
|
||||
|
||||
f.debug_struct("Mutex").field("data", &LockedPlaceholder).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -428,11 +428,18 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for RwLock<T> {
|
||||
impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.try_read() {
|
||||
Ok(guard) => write!(f, "RwLock {{ data: {:?} }}", &*guard),
|
||||
Ok(guard) => f.debug_struct("RwLock").field("data", &&*guard).finish(),
|
||||
Err(TryLockError::Poisoned(err)) => {
|
||||
write!(f, "RwLock {{ data: Poisoned({:?}) }}", &**err.get_ref())
|
||||
f.debug_struct("RwLock").field("data", &&**err.get_ref()).finish()
|
||||
},
|
||||
Err(TryLockError::WouldBlock) => write!(f, "RwLock {{ <locked> }}")
|
||||
Err(TryLockError::WouldBlock) => {
|
||||
struct LockedPlaceholder;
|
||||
impl fmt::Debug for LockedPlaceholder {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("<locked>") }
|
||||
}
|
||||
|
||||
f.debug_struct("RwLock").field("data", &LockedPlaceholder).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,11 +116,18 @@ impl<T> Drop for ReentrantMutex<T> {
|
||||
impl<T: fmt::Debug + 'static> fmt::Debug for ReentrantMutex<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.try_lock() {
|
||||
Ok(guard) => write!(f, "ReentrantMutex {{ data: {:?} }}", &*guard),
|
||||
Ok(guard) => f.debug_struct("ReentrantMutex").field("data", &*guard).finish(),
|
||||
Err(TryLockError::Poisoned(err)) => {
|
||||
write!(f, "ReentrantMutex {{ data: Poisoned({:?}) }}", &**err.get_ref())
|
||||
f.debug_struct("ReentrantMutex").field("data", &**err.get_ref()).finish()
|
||||
},
|
||||
Err(TryLockError::WouldBlock) => write!(f, "ReentrantMutex {{ <locked> }}")
|
||||
Err(TryLockError::WouldBlock) => {
|
||||
struct LockedPlaceholder;
|
||||
impl fmt::Debug for LockedPlaceholder {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("<locked>") }
|
||||
}
|
||||
|
||||
f.debug_struct("ReentrantMutex").field("data", &LockedPlaceholder).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -339,8 +339,11 @@ impl serialize::UseSpecializedDecodable for Span {
|
||||
}
|
||||
|
||||
fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Span {{ lo: {:?}, hi: {:?}, ctxt: {:?} }}",
|
||||
span.lo(), span.hi(), span.ctxt())
|
||||
f.debug_struct("Span")
|
||||
.field("lo", &span.lo())
|
||||
.field("hi", &span.hi())
|
||||
.field("ctxt", &span.ctxt())
|
||||
.finish()
|
||||
}
|
||||
|
||||
impl fmt::Debug for Span {
|
||||
|
Loading…
Reference in New Issue
Block a user