Skip to content

Commit 118a5c4

Browse files
committed
Auto merge of #27129 - arthurprs:debug_atomic, r=alexcrichton
I'm being constantly bitten by the lack of this implementation. I'm unsure if there's a reason to avoid these implementations though. Since we have a "lossy" implementation for both Mutex and RWLock (RWLock {{ locked }}) I don't think there's a big reason for not having a Debug implementation for the atomic types, even if the user can't specify the ordering.
2 parents ed49bad + 225ad17 commit 118a5c4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libcore/atomic.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use intrinsics;
7878
use cell::UnsafeCell;
7979

8080
use default::Default;
81+
use fmt;
8182

8283
/// A boolean type which can be safely shared between threads.
8384
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1089,3 +1090,23 @@ pub fn fence(order: Ordering) {
10891090
}
10901091
}
10911092
}
1093+
1094+
macro_rules! impl_Debug {
1095+
($($t:ident)*) => ($(
1096+
#[stable(feature = "atomic_debug", since = "1.3.0")]
1097+
impl fmt::Debug for $t {
1098+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1099+
f.debug_tuple(stringify!($t)).field(&self.load(Ordering::SeqCst)).finish()
1100+
}
1101+
}
1102+
)*);
1103+
}
1104+
1105+
impl_Debug!{ AtomicUsize AtomicIsize AtomicBool }
1106+
1107+
#[stable(feature = "atomic_debug", since = "1.3.0")]
1108+
impl<T> fmt::Debug for AtomicPtr<T> {
1109+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1110+
f.debug_tuple("AtomicPtr").field(&self.load(Ordering::SeqCst)).finish()
1111+
}
1112+
}

0 commit comments

Comments
 (0)