Skip to content

Commit fafb15f

Browse files
committedNov 21, 2024
Shorten the MaybeUninit Debug implementation
Currently the `Debug` implementation for `MaybeUninit` winds up being pretty verbose. This struct: #[derive(Debug)] pub struct Foo { pub a: u32, pub b: &'static str, pub c: MaybeUninit<u32>, pub d: MaybeUninit<String>, } Prints as: Foo { a: 0, b: "hello", c: core::mem::maybe_uninit::MaybeUninit<u32>, d: core::mem::maybe_uninit::MaybeUninit<alloc::string::String>, } The goal is just to be a standin for content so the path prefix doesn't add any useful information. Change the implementation to trim `MaybeUninit`'s leading path, meaning the new result is now: Foo { a: 0, b: "hello", c: MaybeUninit<u32>, d: MaybeUninit<alloc::string::String>, }
1 parent 318f96a commit fafb15f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎library/core/src/mem/maybe_uninit.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ impl<T: Copy> Clone for MaybeUninit<T> {
255255
#[stable(feature = "maybe_uninit_debug", since = "1.41.0")]
256256
impl<T> fmt::Debug for MaybeUninit<T> {
257257
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
258-
f.pad(type_name::<Self>())
258+
let full_name = type_name::<Self>();
259+
// NB: this needs to be changed if `MaybeUninit` moves modules
260+
let short_name = full_name.split_once("mem::maybe_uninit::").unwrap().1;
261+
f.pad(short_name)
259262
}
260263
}
261264

0 commit comments

Comments
 (0)