Skip to content

Commit bb2db94

Browse files
Rollup merge of rust-lang#42822 - ChrisMacNaughton:guard-traits, r=alexcrichton
Ensure Guard types impl Display & Debug Fixes rust-lang#24372
2 parents f3aebb0 + 14df549 commit bb2db94

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/libcore/cell.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,13 @@ impl<'b, T: ?Sized> Ref<'b, T> {
942942
#[unstable(feature = "coerce_unsized", issue = "27732")]
943943
impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Ref<'b, U>> for Ref<'b, T> {}
944944

945+
#[stable(feature = "std_guard_impls", since = "1.20")]
946+
impl<'a, T: ?Sized + fmt::Display> fmt::Display for Ref<'a, T> {
947+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
948+
self.value.fmt(f)
949+
}
950+
}
951+
945952
impl<'b, T: ?Sized> RefMut<'b, T> {
946953
/// Make a new `RefMut` for a component of the borrowed data, e.g. an enum
947954
/// variant.
@@ -1034,6 +1041,13 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
10341041
#[unstable(feature = "coerce_unsized", issue = "27732")]
10351042
impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<RefMut<'b, U>> for RefMut<'b, T> {}
10361043

1044+
#[stable(feature = "std_guard_impls", since = "1.20")]
1045+
impl<'a, T: ?Sized + fmt::Display> fmt::Display for RefMut<'a, T> {
1046+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1047+
self.value.fmt(f)
1048+
}
1049+
}
1050+
10371051
/// The core primitive for interior mutability in Rust.
10381052
///
10391053
/// `UnsafeCell<T>` is a type that wraps some `T` and indicates unsafe interior operations on the

src/libstd/sync/mutex.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,13 @@ impl<'a, T: ?Sized + fmt::Debug> fmt::Debug for MutexGuard<'a, T> {
440440
}
441441
}
442442

443+
#[stable(feature = "std_guard_impls", since = "1.20")]
444+
impl<'a, T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'a, T> {
445+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
446+
(**self).fmt(f)
447+
}
448+
}
449+
443450
pub fn guard_lock<'a, T: ?Sized>(guard: &MutexGuard<'a, T>) -> &'a sys::Mutex {
444451
&guard.__lock.inner
445452
}

src/libstd/sync/rwlock.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockReadGuard<'a, T> {
370370
}
371371
}
372372

373+
#[stable(feature = "std_guard_impls", since = "1.20")]
374+
impl<'a, T: ?Sized + fmt::Display> fmt::Display for RwLockReadGuard<'a, T> {
375+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
376+
(**self).fmt(f)
377+
}
378+
}
379+
373380
#[stable(feature = "std_debug", since = "1.16.0")]
374381
impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> {
375382
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -379,6 +386,13 @@ impl<'a, T: fmt::Debug> fmt::Debug for RwLockWriteGuard<'a, T> {
379386
}
380387
}
381388

389+
#[stable(feature = "std_guard_impls", since = "1.20")]
390+
impl<'a, T: ?Sized + fmt::Display> fmt::Display for RwLockWriteGuard<'a, T> {
391+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
392+
(**self).fmt(f)
393+
}
394+
}
395+
382396
#[stable(feature = "rust1", since = "1.0.0")]
383397
impl<'rwlock, T: ?Sized> Deref for RwLockReadGuard<'rwlock, T> {
384398
type Target = T;

0 commit comments

Comments
 (0)