]> git.lizzy.rs Git - rust.git/commitdiff
Ensure Guard types impl Display & Debug
authorChris MacNaughton <chris.macnaughton@canonical.com>
Thu, 22 Jun 2017 10:01:22 +0000 (12:01 +0200)
committerChris MacNaughton <chris.macnaughton@canonical.com>
Thu, 22 Jun 2017 14:54:32 +0000 (16:54 +0200)
Fixes #24372

src/libcore/cell.rs
src/libstd/sync/mutex.rs
src/libstd/sync/rwlock.rs

index e75401f6ce031de718093fcb549c3019b31eba17..1eebf67ad04cb893a234804b59913255902dab9b 100644 (file)
@@ -942,6 +942,13 @@ pub fn map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Ref<'b, U>
 #[unstable(feature = "coerce_unsized", issue = "27732")]
 impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Ref<'b, U>> 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 @@ fn deref_mut(&mut self) -> &mut T {
 #[unstable(feature = "coerce_unsized", issue = "27732")]
 impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<RefMut<'b, U>> 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<T>` is a type that wraps some `T` and indicates unsafe interior operations on the
index 9a242a96d46e3cf36307dc475ec701b2c5191ea8..fc6c7de9ef083a753f0d91067c36e3f9688baeec 100644 (file)
@@ -440,6 +440,13 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[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
 }
index 95bc8d3093286cd57a511f392175e5c1bcf5a1d0..944801e8a3bf021ee131a395a8458393372248c0 100644 (file)
@@ -370,6 +370,13 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[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 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[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;