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.
This commit is contained in:
bors 2015-07-21 00:03:37 +00:00
commit 118a5c4c34

View File

@ -78,6 +78,7 @@ use intrinsics;
use cell::UnsafeCell;
use default::Default;
use fmt;
/// A boolean type which can be safely shared between threads.
#[stable(feature = "rust1", since = "1.0.0")]
@ -1089,3 +1090,23 @@ pub fn fence(order: Ordering) {
}
}
}
macro_rules! impl_Debug {
($($t:ident)*) => ($(
#[stable(feature = "atomic_debug", since = "1.3.0")]
impl fmt::Debug for $t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple(stringify!($t)).field(&self.load(Ordering::SeqCst)).finish()
}
}
)*);
}
impl_Debug!{ AtomicUsize AtomicIsize AtomicBool }
#[stable(feature = "atomic_debug", since = "1.3.0")]
impl<T> fmt::Debug for AtomicPtr<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("AtomicPtr").field(&self.load(Ordering::SeqCst)).finish()
}
}