Skip to content

Commit 82e83c7

Browse files
committed
Implement Debug for ptr::Shared and ptr::Unique.
Fixes #46755.
1 parent edbd7d2 commit 82e83c7

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
@@ -2334,7 +2334,6 @@ impl<T: ?Sized> PartialOrd for *mut T {
23342334
///
23352335
/// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
23362336
/// for any type which upholds Unique's aliasing requirements.
2337-
#[allow(missing_debug_implementations)]
23382337
#[unstable(feature = "unique", reason = "needs an RFC to flesh out design",
23392338
issue = "27730")]
23402339
pub struct Unique<T: ?Sized> {
@@ -2347,6 +2346,13 @@ pub struct Unique<T: ?Sized> {
23472346
_marker: PhantomData<T>,
23482347
}
23492348

2349+
#[unstable(feature = "unique", issue = "27730")]
2350+
impl<T: ?Sized> fmt::Debug for Unique<T> {
2351+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2352+
write!(f, "{:p}", self.as_ptr())
2353+
}
2354+
}
2355+
23502356
/// `Unique` pointers are `Send` if `T` is `Send` because the data they
23512357
/// reference is unaliased. Note that this aliasing invariant is
23522358
/// unenforced by the type system; the abstraction using the
@@ -2467,13 +2473,19 @@ impl<'a, T: ?Sized> From<&'a T> for Unique<T> {
24672473
/// Usually this won't be necessary; covariance is correct for most safe abstractions,
24682474
/// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
24692475
/// provide a public API that follows the normal shared XOR mutable rules of Rust.
2470-
#[allow(missing_debug_implementations)]
24712476
#[unstable(feature = "shared", reason = "needs an RFC to flesh out design",
24722477
issue = "27730")]
24732478
pub struct Shared<T: ?Sized> {
24742479
pointer: NonZero<*const T>,
24752480
}
24762481

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

0 commit comments

Comments
 (0)