Skip to content

Commit

Permalink
Implement Debug for MaybeUninit
Browse files Browse the repository at this point in the history
Precedent: UnsafeCell implements Debug even though it can't actually
display the value.
  • Loading branch information
petertodd committed Nov 7, 2019
1 parent 87cbf0a commit 8fad66b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libcore/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::any::type_name;
use crate::fmt;
use crate::intrinsics;
use crate::mem::ManuallyDrop;

Expand Down Expand Up @@ -230,6 +232,13 @@ impl<T: Copy> Clone for MaybeUninit<T> {
}
}

#[stable(feature = "maybe_uninit_debug", since = "1.41.0")]
impl<T> fmt::Debug for MaybeUninit<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad(type_name::<Self>())
}
}

impl<T> MaybeUninit<T> {
/// Creates a new `MaybeUninit<T>` initialized with the given value.
/// It is safe to call [`assume_init`] on the return value of this function.
Expand Down

0 comments on commit 8fad66b

Please sign in to comment.