Skip to content

Commit

Permalink
Remove minor future footgun in impl Debug for MaybeUninit
Browse files Browse the repository at this point in the history
No longer breaks if `MaybeUninit` moves modules (technically it could break if `MaybeUninit` were renamed but realistically that will never happen)
  • Loading branch information
Sky9x authored and gitbot committed Feb 20, 2025
1 parent e5f6d8f commit 54d3b74
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,9 @@ impl<T: Copy> Clone for MaybeUninit<T> {
impl<T> fmt::Debug for MaybeUninit<T> {
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<{..}>").
// This needs to be adjusted if `MaybeUninit` moves modules.
let full_name = type_name::<Self>();
let short_name = full_name.split_once("mem::maybe_uninit::").unwrap().1;
f.pad(short_name)
let prefix_len = full_name.find("MaybeUninit").unwrap();
f.pad(&full_name[prefix_len..])
}
}

Expand Down

0 comments on commit 54d3b74

Please sign in to comment.