From a145b80be079fd6b299270f7fb97ed5ce0452d32 Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Sat, 28 Dec 2019 21:33:36 +0100 Subject: [PATCH] Constify Result --- src/libcore/lib.rs | 2 ++ src/libcore/result.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 7d11dd2800fd4..80310ebee7bce 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -72,8 +72,10 @@ #![feature(concat_idents)] #![feature(const_fn)] #![feature(const_fn_union)] +#![feature(const_if_match)] #![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 ce4c8995a3c48..8e62a3e8f71f0 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -278,9 +278,10 @@ impl Result { /// 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 Result { /// 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 Result { /// 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),