1
Fork 0

Rollup merge of #136271 - Sky9x:debug-maybeuninit-footgun, r=tgross35

Remove minor future footgun in `impl Debug for MaybeUninit`

No longer breaks if `MaybeUninit` moves modules (technically it could break if `MaybeUninit` were renamed but realistically that will never happen)

Debug impl originally added in #133282
This commit is contained in:
Matthias Krüger 2025-01-30 20:47:08 +01:00 committed by GitHub
commit 410442f610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -276,10 +276,9 @@ impl<T: Copy> Clone for MaybeUninit<T> {
impl<T> fmt::Debug for MaybeUninit<T> { impl<T> fmt::Debug for MaybeUninit<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("MaybeUninit<{..}>"). // NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("MaybeUninit<{..}>").
// This needs to be adjusted if `MaybeUninit` moves modules.
let full_name = type_name::<Self>(); let full_name = type_name::<Self>();
let short_name = full_name.split_once("mem::maybe_uninit::").unwrap().1; let prefix_len = full_name.find("MaybeUninit").unwrap();
f.pad(short_name) f.pad(&full_name[prefix_len..])
} }
} }