From d22f27a6d6c8096d164fd150013315cf6742b91e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 21:42:25 -0500 Subject: [PATCH 1/2] Implement `Debug` for `Padding` Use the `MaybeUninit` formatting so this prints as `Padding` or similar. --- src/types.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/types.rs b/src/types.rs index 3ef8177c5feca..8be1c2d2e43df 100644 --- a/src/types.rs +++ b/src/types.rs @@ -17,6 +17,16 @@ impl Default for Padding { } } +impl fmt::Debug for Padding { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Taken frmo `MaybeUninit`'s debug implementation + // NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("Padding<{..}>"). + let full_name = core::any::type_name::(); + let prefix_len = full_name.find("Padding").unwrap(); + f.pad(&full_name[prefix_len..]) + } +} + /// The default repr type used for C style enums in Rust. #[cfg(target_env = "msvc")] #[allow(unused)] From deacfcc406abc4c91398338c2d182721a4fe126e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 22 Sep 2025 21:47:24 -0500 Subject: [PATCH 2/2] Add a note about why `Padding` requires `T: Copy` --- src/types.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types.rs b/src/types.rs index 8be1c2d2e43df..7d49a425d59ea 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,6 +6,9 @@ use crate::prelude::*; /// A transparent wrapper over `MaybeUninit` to represent uninitialized padding /// while providing `Default`. +// This is restricted to `Copy` types since that's a loose indicator that zeros is actually +// a valid bitpattern. There is no technical reason this is required, though, so it could be +// lifted in the future if it becomes a problem. #[allow(unused)] #[repr(transparent)] #[derive(Clone, Copy)]