Skip to content

Commit ee8187a

Browse files
Enseliclukas-code
andcommitted
core: Use Formatter::debug_struct() in Debug impl of raw pointers
Co-authored-by: Lukas <26522220+lukas-code@users.noreply.github.com>
1 parent 5508583 commit ee8187a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

library/core/src/fmt/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2770,11 +2770,10 @@ impl<T: ?Sized> Pointer for *const T {
27702770
if core::mem::size_of::<<T as core::ptr::Pointee>::Metadata>() == 0 {
27712771
pointer_fmt_inner(self.expose_provenance(), f)
27722772
} else {
2773-
f.write_str("Pointer { addr: ")?;
2774-
pointer_fmt_inner(self.expose_provenance(), f)?;
2775-
f.write_str(", metadata: ")?;
2776-
Debug::fmt(&core::ptr::metadata(*self), f)?;
2777-
f.write_str(" }")
2773+
f.debug_struct("Pointer")
2774+
.field_with("addr", |f| pointer_fmt_inner(self.expose_provenance(), f))
2775+
.field("metadata", &core::ptr::metadata(*self))
2776+
.finish()
27782777
}
27792778
}
27802779
}

0 commit comments

Comments
 (0)