Skip to content

Commit ba5d7a6

Browse files
frewsxcvSimonSapin
authored andcommitted
Implement Debug for ptr::Shared and ptr::Unique.
Fixes #46755.
1 parent 816d765 commit ba5d7a6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/libcore/ptr.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,6 @@ impl<T: ?Sized> PartialOrd for *mut T {
23302330
///
23312331
/// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
23322332
/// for any type which upholds Unique's aliasing requirements.
2333-
#[allow(missing_debug_implementations)]
23342333
#[unstable(feature = "unique", reason = "needs an RFC to flesh out design",
23352334
issue = "27730")]
23362335
pub struct Unique<T: ?Sized> {
@@ -2343,6 +2342,13 @@ pub struct Unique<T: ?Sized> {
23432342
_marker: PhantomData<T>,
23442343
}
23452344

2345+
#[unstable(feature = "unique", issue = "27730")]
2346+
impl<T: ?Sized> fmt::Debug for Unique<T> {
2347+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2348+
write!(f, "{:p}", self.as_ptr())
2349+
}
2350+
}
2351+
23462352
/// `Unique` pointers are `Send` if `T` is `Send` because the data they
23472353
/// reference is unaliased. Note that this aliasing invariant is
23482354
/// unenforced by the type system; the abstraction using the
@@ -2463,13 +2469,19 @@ impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
24632469
/// Usually this won't be necessary; covariance is correct for most safe abstractions,
24642470
/// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
24652471
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
2466-
#[allow(missing_debug_implementations)]
24672472
#[unstable(feature = "shared", reason = "needs an RFC to flesh out design",
24682473
issue = "27730")]
24692474
pub struct Shared<T: ?Sized> {
24702475
pointer: NonZero<*const T>,
24712476
}
24722477

2478+
#[unstable(feature = "shared", issue = "27730")]
2479+
impl<T: ?Sized> fmt::Debug for Shared<T> {
2480+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2481+
write!(f, "{:p}", self.as_ptr())
2482+
}
2483+
}
2484+
24732485
/// `Shared` pointers are not `Send` because the data they reference may be aliased.
24742486
// NB: This impl is unnecessary, but should provide better error messages.
24752487
#[unstable(feature = "shared", issue = "27730")]

0 commit comments

Comments
 (0)