]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #90269 - woppopo:const_option_expect, r=yaahc
authorMatthias Krüger <matthias.krueger@famsik.de>
Fri, 3 Dec 2021 05:24:11 +0000 (06:24 +0100)
committerGitHub <noreply@github.com>
Fri, 3 Dec 2021 05:24:11 +0000 (06:24 +0100)
Make `Option::expect` unstably const

Tracking issue: #67441

library/core/src/option.rs

index 4eeb5e43943862dd7d7f9a57d5d3dc49a3db51c6..6e9b388a2bd0721604d0095b237787eb27bbd287 100644 (file)
@@ -703,7 +703,8 @@ pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut 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 @@ pub const fn transpose(self) -> Result<Option<T>, E> {
 #[inline(never)]
 #[cold]
 #[track_caller]
-fn expect_failed(msg: &str) -> ! {
+const fn expect_failed(msg: &str) -> ! {
     panic!("{}", msg)
 }