about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCDirkx <christiaan@dirkx.com>2020-08-31 02:43:17 +0200
committerCDirkx <christiaan@dirkx.com>2020-08-31 02:43:17 +0200
commit518f1ccb728aa03665e51710c12973a74cc98df5 (patch)
tree09ddba686c715b43c2ea43f3c00df448da10c42b
parent36b0d7e25769e88fec85e1d073196065a7f2d7c4 (diff)
downloadrust-518f1ccb728aa03665e51710c12973a74cc98df5.tar.gz
rust-518f1ccb728aa03665e51710c12973a74cc98df5.zip
Stabilize some Result methods as const
Stabilize the following methods of `Result` as const:
 - `is_ok`
 - `is_err`
 - `as_ref`

Possible because of stabilization of #49146 (Allow if and match in constants).
-rw-r--r--library/core/src/lib.rs1
-rw-r--r--library/core/src/result.rs6
-rw-r--r--src/test/ui/consts/const-result.rs12
3 files changed, 15 insertions, 4 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index aef82a5aec5..290540829e0 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -87,7 +87,6 @@
 #![feature(const_ptr_offset)]
 #![feature(const_ptr_offset_from)]
 #![feature(const_raw_ptr_comparison)]
-#![feature(const_result)]
 #![feature(const_slice_from_raw_parts)]
 #![feature(const_slice_ptr_len)]
 #![feature(const_size_of_val)]
diff --git a/library/core/src/result.rs b/library/core/src/result.rs
index ce0fc628e11..5cec183c237 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -273,7 +273,7 @@ impl<T, E> Result<T, E> {
     /// assert_eq!(x.is_ok(), false);
     /// ```
     #[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
-    #[rustc_const_unstable(feature = "const_result", issue = "67520")]
+    #[rustc_const_stable(feature = "const_result", since = "1.48.0")]
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const fn is_ok(&self) -> bool {
@@ -294,7 +294,7 @@ impl<T, E> Result<T, E> {
     /// assert_eq!(x.is_err(), true);
     /// ```
     #[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
-    #[rustc_const_unstable(feature = "const_result", issue = "67520")]
+    #[rustc_const_stable(feature = "const_result", since = "1.48.0")]
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const fn is_err(&self) -> bool {
@@ -438,7 +438,7 @@ impl<T, E> Result<T, E> {
     /// assert_eq!(x.as_ref(), Err(&"Error"));
     /// ```
     #[inline]
-    #[rustc_const_unstable(feature = "const_result", issue = "67520")]
+    #[rustc_const_stable(feature = "const_result", since = "1.48.0")]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const fn as_ref(&self) -> Result<&T, &E> {
         match *self {
diff --git a/src/test/ui/consts/const-result.rs b/src/test/ui/consts/const-result.rs
new file mode 100644
index 00000000000..e548d3e79ff
--- /dev/null
+++ b/src/test/ui/consts/const-result.rs
@@ -0,0 +1,12 @@
+// run-pass
+
+fn main() {
+    const X: Result<i32, bool> = Ok(32);
+    const Y: Result<&i32, &bool> = X.as_ref();
+
+    const IS_OK: bool = X.is_ok();
+    assert!(IS_OK);
+
+    const IS_ERR: bool = Y.is_err();
+    assert!(!IS_ERR)
+}