From ba5d7a66e847f5713633cb792c379a11b774e21f Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 17 Dec 2017 17:28:01 -0500 Subject: [PATCH] Implement Debug for ptr::Shared and ptr::Unique. Fixes https://github.com/rust-lang/rust/issues/46755. --- src/libcore/ptr.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 7f7246df8f2..4da51a33128 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2330,7 +2330,6 @@ fn ge(&self, other: &*mut T) -> bool { *self >= *other } /// /// Unlike `*mut T`, `Unique` is covariant over `T`. This should always be correct /// for any type which upholds Unique's aliasing requirements. -#[allow(missing_debug_implementations)] #[unstable(feature = "unique", reason = "needs an RFC to flesh out design", issue = "27730")] pub struct Unique { @@ -2343,6 +2342,13 @@ pub struct Unique { _marker: PhantomData, } +#[unstable(feature = "unique", issue = "27730")] +impl fmt::Debug for Unique { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:p}", self.as_ptr()) + } +} + /// `Unique` pointers are `Send` if `T` is `Send` because the data they /// reference is unaliased. Note that this aliasing invariant is /// unenforced by the type system; the abstraction using the @@ -2463,13 +2469,19 @@ fn from(reference: &'a T) -> Self { /// Usually this won't be necessary; covariance is correct for most safe abstractions, /// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they /// provide a public API that follows the normal shared XOR mutable rules of Rust. -#[allow(missing_debug_implementations)] #[unstable(feature = "shared", reason = "needs an RFC to flesh out design", issue = "27730")] pub struct Shared { pointer: NonZero<*const T>, } +#[unstable(feature = "shared", issue = "27730")] +impl fmt::Debug for Shared { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:p}", self.as_ptr()) + } +} + /// `Shared` pointers are not `Send` because the data they reference may be aliased. // NB: This impl is unnecessary, but should provide better error messages. #[unstable(feature = "shared", issue = "27730")]