From 7430b22b5f83ac20cf51a76c1e755aa6e14557a0 Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 26 Oct 2021 00:41:39 +0900 Subject: [PATCH] Make `Option::expect` const --- library/core/src/option.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index f4ce7d1dfb334..7dfbbe9cd950e 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -703,7 +703,8 @@ impl 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), @@ -1634,7 +1635,7 @@ impl Option> { #[inline(never)] #[cold] #[track_caller] -fn expect_failed(msg: &str) -> ! { +const fn expect_failed(msg: &str) -> ! { panic!("{}", msg) }