about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-03 06:24:11 +0100
committerGitHub <noreply@github.com>2021-12-03 06:24:11 +0100
commit94cd0259f247c4cadb2942e8f6fe52ff9fc2422b (patch)
treebce47473819bcb374bcc784c0a33df5b63766b74
parent31003a3089cce2a918a9c8b73a77781d19c5f1d8 (diff)
parent7430b22b5f83ac20cf51a76c1e755aa6e14557a0 (diff)
downloadrust-94cd0259f247c4cadb2942e8f6fe52ff9fc2422b.tar.gz
rust-94cd0259f247c4cadb2942e8f6fe52ff9fc2422b.zip
Rollup merge of #90269 - woppopo:const_option_expect, r=yaahc
Make `Option::expect` unstably const

Tracking issue: #67441
-rw-r--r--library/core/src/option.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index 4eeb5e43943..6e9b388a2bd 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -703,7 +703,8 @@ impl<T> Option<T> {
     #[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 @@ impl<T, E> Option<Result<T, E>> {
 #[inline(never)]
 #[cold]
 #[track_caller]
-fn expect_failed(msg: &str) -> ! {
+const fn expect_failed(msg: &str) -> ! {
     panic!("{}", msg)
 }