]> git.lizzy.rs Git - rust.git/commitdiff
Make `Option::unwrap` unstably const
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Thu, 30 Jul 2020 19:30:56 +0000 (12:30 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Thu, 30 Jul 2020 19:30:58 +0000 (12:30 -0700)
`Result::unwrap` is not eligible becuase it formats the contents of the
`Err` variant. `unwrap_or`, `unwrap_or_else` and friends are not
eligible because they drop things or invoke closures.

library/core/src/lib.rs
library/core/src/option.rs

index 550e07f9d571091b487574ab9cd03bd302d27f13..46a6ec09962bcf3ba5a1c838bf34b00402182ee8 100644 (file)
@@ -82,6 +82,7 @@
 #![feature(const_fn_union)]
 #![feature(const_generics)]
 #![feature(const_option)]
+#![feature(const_precise_live_drops)]
 #![feature(const_ptr_offset)]
 #![feature(const_ptr_offset_from)]
 #![feature(const_raw_ptr_comparison)]
index 5932f8e5856a74c7aafb67e98a95f2ec0e8118fb..3c7211fe040dcd384226f59d85ebedd29d9ed00c 100644 (file)
@@ -380,7 +380,8 @@ pub fn expect(self, msg: &str) -> T {
     #[inline]
     #[track_caller]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn unwrap(self) -> T {
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
+    pub const fn unwrap(self) -> T {
         match self {
             Some(val) => val,
             None => panic!("called `Option::unwrap()` on a `None` value"),