about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-31 19:19:33 +0100
committerGitHub <noreply@github.com>2019-12-31 19:19:33 +0100
commit89fbed98c260fa30bf54138b3c8677f3d17845e2 (patch)
treec41e553a488c754c3421d65cd18490c74de2453f /src/libcore
parent3cf2bc0e51f012b0fb590536a9125c7b67883bb9 (diff)
parent954c432a87fc5069ac10cc5a92fd44106be1e7fd (diff)
downloadrust-89fbed98c260fa30bf54138b3c8677f3d17845e2.tar.gz
rust-89fbed98c260fa30bf54138b3c8677f3d17845e2.zip
Rollup merge of #67685 - lukaslueg:const_result, r=oli-obk
Constify Result

r? @oli-obk

This is just the `Result`-part of #67494 which I'll resubmit once #66254 has landed.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/lib.rs1
-rw-r--r--src/libcore/result.rs9
2 files changed, 7 insertions, 3 deletions
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 590f4e46c1d..8e1273c3172 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -76,6 +76,7 @@
 #![feature(const_fn_union)]
 #![feature(const_generics)]
 #![feature(const_ptr_offset_from)]
+#![feature(const_result)]
 #![feature(const_type_name)]
 #![feature(custom_inner_attributes)]
 #![feature(decl_macro)]
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 5628658c5bd..5cfc81097dd 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -278,9 +278,10 @@ 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")]
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn is_ok(&self) -> bool {
+    pub const fn is_ok(&self) -> bool {
         match *self {
             Ok(_) => true,
             Err(_) => false,
@@ -303,9 +304,10 @@ 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")]
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn is_err(&self) -> bool {
+    pub const fn is_err(&self) -> bool {
         !self.is_ok()
     }
 
@@ -446,8 +448,9 @@ impl<T, E> Result<T, E> {
     /// assert_eq!(x.as_ref(), Err(&"Error"));
     /// ```
     #[inline]
+    #[rustc_const_unstable(feature = "const_result", issue = "67520")]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn as_ref(&self) -> Result<&T, &E> {
+    pub const fn as_ref(&self) -> Result<&T, &E> {
         match *self {
             Ok(ref x) => Ok(x),
             Err(ref x) => Err(x),