Skip to content

Commit d9087cb

Browse files
Added a panic-on-uninhabited guard on get_ref and get_mut
1 parent 2ebf5e6 commit d9087cb

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libcore/mem/maybe_uninit.rs

+2
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ impl<T> MaybeUninit<T> {
571571
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
572572
#[inline(always)]
573573
pub unsafe fn get_ref(&self) -> &T {
574+
intrinsics::panic_if_uninhabited::<T>();
574575
&*self.value
575576
}
576577

@@ -690,6 +691,7 @@ impl<T> MaybeUninit<T> {
690691
#[unstable(feature = "maybe_uninit_ref", issue = "63568")]
691692
#[inline(always)]
692693
pub unsafe fn get_mut(&mut self) -> &mut T {
694+
intrinsics::panic_if_uninhabited::<T>();
693695
&mut *self.value
694696
}
695697

0 commit comments

Comments
 (0)