diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 4eeb5e439438..6e9b388a2bd0 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -703,7 +703,8 @@ pub fn as_pin_mut(self: Pin<&mut Self>) -> Option> { #[inline] #[track_caller] #[stable(feature = "rust1", since = "1.0.0")] - pub fn expect(self, msg: &str) -> T { + #[rustc_const_unstable(feature = "const_option", issue = "67441")] + pub const fn expect(self, msg: &str) -> T { match self { Some(val) => val, None => expect_failed(msg), @@ -1658,7 +1659,7 @@ pub const fn transpose(self) -> Result, E> { #[inline(never)] #[cold] #[track_caller] -fn expect_failed(msg: &str) -> ! { +const fn expect_failed(msg: &str) -> ! { panic!("{}", msg) }