about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBenoît du Garreau <bdgdlm@outlook.com>2020-07-01 15:07:23 +0200
committerBenoît du Garreau <bdgdlm@outlook.com>2020-07-01 18:14:03 +0200
commite7d9944e205dc59f1174b584cd8ed41deced9646 (patch)
tree6cc71bd500e61cd62d60d6f71f9b9ff4de013b49 /src/libcore
parentd462551a8600e57d8b6f87e71ea56868bc5da6cf (diff)
downloadrust-e7d9944e205dc59f1174b584cd8ed41deced9646.tar.gz
rust-e7d9944e205dc59f1174b584cd8ed41deced9646.zip
Add feature const_option
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/lib.rs1
-rw-r--r--src/libcore/option.rs12
2 files changed, 9 insertions, 4 deletions
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index aeb52bffbf2..2aeb105bca2 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -85,6 +85,7 @@
 #![feature(const_panic)]
 #![feature(const_fn_union)]
 #![feature(const_generics)]
+#![feature(const_option)]
 #![feature(const_ptr_offset)]
 #![feature(const_ptr_offset_from)]
 #![cfg_attr(not(bootstrap), feature(const_raw_ptr_comparison))]
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 7aca6af3de6..7ba244214ae 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -179,8 +179,9 @@ impl<T> Option<T> {
     /// [`Some`]: #variant.Some
     #[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"]
     #[inline]
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn is_some(&self) -> bool {
+    pub const fn is_some(&self) -> bool {
         matches!(*self, Some(_))
     }
 
@@ -200,8 +201,9 @@ impl<T> Option<T> {
     #[must_use = "if you intended to assert that this doesn't have a value, consider \
                   `.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"]
     #[inline]
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn is_none(&self) -> bool {
+    pub const fn is_none(&self) -> bool {
         !self.is_some()
     }
 
@@ -259,8 +261,9 @@ impl<T> Option<T> {
     /// println!("still can print text: {:?}", text);
     /// ```
     #[inline]
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn as_ref(&self) -> Option<&T> {
+    pub const fn as_ref(&self) -> Option<&T> {
         match *self {
             Some(ref x) => Some(x),
             None => None,
@@ -580,8 +583,9 @@ impl<T> Option<T> {
     /// assert_eq!(x.iter().next(), None);
     /// ```
     #[inline]
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn iter(&self) -> Iter<'_, T> {
+    pub const fn iter(&self) -> Iter<'_, T> {
         Iter { inner: Item { opt: self.as_ref() } }
     }