From d9087cb388c00ec9a53f7a3049afb2ce00ce56fa Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Wed, 30 Oct 2019 14:52:56 +0100 Subject: [PATCH] Added a panic-on-uninhabited guard on get_ref and get_mut --- src/libcore/mem/maybe_uninit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index 60d20735db4..d5893dd1d58 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -571,6 +571,7 @@ impl MaybeUninit { #[unstable(feature = "maybe_uninit_ref", issue = "63568")] #[inline(always)] pub unsafe fn get_ref(&self) -> &T { + intrinsics::panic_if_uninhabited::(); &*self.value } @@ -690,6 +691,7 @@ impl MaybeUninit { #[unstable(feature = "maybe_uninit_ref", issue = "63568")] #[inline(always)] pub unsafe fn get_mut(&mut self) -> &mut T { + intrinsics::panic_if_uninhabited::(); &mut *self.value }