From 14df54989aecb437e9cf6f3e066553cfbc979e26 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Thu, 22 Jun 2017 12:01:22 +0200 Subject: [PATCH] Ensure Guard types impl Display & Debug Fixes #24372 --- src/libcore/cell.rs | 14 ++++++++++++++ src/libstd/sync/mutex.rs | 7 +++++++ src/libstd/sync/rwlock.rs | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index e75401f6ce0..1eebf67ad04 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -942,6 +942,13 @@ impl<'b, T: ?Sized> Ref<'b, T> { #[unstable(feature = "coerce_unsized", issue = "27732")] impl<'b, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized> for Ref<'b, T> {} +#[stable(feature = "std_guard_impls", since = "1.20")] +impl<'a, T: ?Sized + fmt::Display> fmt::Display for Ref<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.value.fmt(f) + } +} + impl<'b, T: ?Sized> RefMut<'b, T> { /// Make a new `RefMut` for a component of the borrowed data, e.g. an enum /// variant. @@ -1034,6 +1041,13 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> { #[unstable(feature = "coerce_unsized", issue = "27732")] impl<'b, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized> for RefMut<'b, T> {} +#[stable(feature = "std_guard_impls", since = "1.20")] +impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.value.fmt(f) + } +} + /// The core primitive for interior mutability in Rust. /// /// `UnsafeCell` is a type that wraps some `T` and indicates unsafe interior operations on the diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 9a242a96d46..fc6c7de9ef0 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -440,6 +440,13 @@ impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> { } } +#[stable(feature = "std_guard_impls", since = "1.20")] +impl<'a, T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + (**self).fmt(f) + } +} + pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::Mutex { &guard.__lock.inner } diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 95bc8d30932..944801e8a3b 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -370,6 +370,13 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> { } } +#[stable(feature = "std_guard_impls", since = "1.20")] +impl<'a, T: ?Sized + fmt::Display> fmt::Display for RwLockReadGuard<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + (**self).fmt(f) + } +} + #[stable(feature = "std_debug", since = "1.16.0")] impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -379,6 +386,13 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> { } } +#[stable(feature = "std_guard_impls", since = "1.20")] +impl<'a, T: ?Sized + fmt::Display> fmt::Display for RwLockWriteGuard<'a, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + (**self).fmt(f) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> { type Target = T;