Skip to content

Commit d22ebf0

Browse files
authored
Rollup merge of rust-lang#97225 - cuviper:ref-display, r=scottmcm
Fix `Display` for `cell::{Ref,RefMut}` These guards changed to pointers in rust-lang#97027, but their `Display` was formatting that field directly, which made it show the raw pointer value. Now we go through `Deref` to display the real value again. Miri noticed this change, rust-lang#97204, so hopefully that will be fixed.
2 parents e1340f2 + 83abb7c commit d22ebf0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

library/core/src/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Ref<'b, U>> for Ref<'b,
14871487
#[stable(feature = "std_guard_impls", since = "1.20.0")]
14881488
impl<T: ?Sized + fmt::Display> fmt::Display for Ref<'_, T> {
14891489
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1490-
self.value.fmt(f)
1490+
(**self).fmt(f)
14911491
}
14921492
}
14931493

@@ -1735,7 +1735,7 @@ impl<'b, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<RefMut<'b, U>> for RefM
17351735
#[stable(feature = "std_guard_impls", since = "1.20.0")]
17361736
impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
17371737
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1738-
self.value.fmt(f)
1738+
(**self).fmt(f)
17391739
}
17401740
}
17411741

library/core/tests/cell.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ fn ref_and_refmut_have_sensible_show() {
7373
let refcell = RefCell::new("foo");
7474

7575
let refcell_refmut = refcell.borrow_mut();
76-
assert!(format!("{refcell_refmut:?}").contains("foo"));
76+
assert_eq!(format!("{refcell_refmut}"), "foo"); // Display
77+
assert!(format!("{refcell_refmut:?}").contains("foo")); // Debug
7778
drop(refcell_refmut);
7879

7980
let refcell_ref = refcell.borrow();
80-
assert!(format!("{refcell_ref:?}").contains("foo"));
81+
assert_eq!(format!("{refcell_ref}"), "foo"); // Display
82+
assert!(format!("{refcell_ref:?}").contains("foo")); // Debug
8183
drop(refcell_ref);
8284
}
8385

0 commit comments

Comments
 (0)