Skip to content

Commit 954c432

Browse files
committed
Constify Result
1 parent 71bb0ff commit 954c432

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#![feature(const_fn_union)]
7777
#![feature(const_generics)]
7878
#![feature(const_ptr_offset_from)]
79+
#![feature(const_result)]
7980
#![feature(const_type_name)]
8081
#![feature(custom_inner_attributes)]
8182
#![feature(decl_macro)]

src/libcore/result.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ impl<T, E> Result<T, E> {
278278
/// assert_eq!(x.is_ok(), false);
279279
/// ```
280280
#[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
281+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
281282
#[inline]
282283
#[stable(feature = "rust1", since = "1.0.0")]
283-
pub fn is_ok(&self) -> bool {
284+
pub const fn is_ok(&self) -> bool {
284285
match *self {
285286
Ok(_) => true,
286287
Err(_) => false,
@@ -303,9 +304,10 @@ impl<T, E> Result<T, E> {
303304
/// assert_eq!(x.is_err(), true);
304305
/// ```
305306
#[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
307+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
306308
#[inline]
307309
#[stable(feature = "rust1", since = "1.0.0")]
308-
pub fn is_err(&self) -> bool {
310+
pub const fn is_err(&self) -> bool {
309311
!self.is_ok()
310312
}
311313

@@ -446,8 +448,9 @@ impl<T, E> Result<T, E> {
446448
/// assert_eq!(x.as_ref(), Err(&"Error"));
447449
/// ```
448450
#[inline]
451+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
449452
#[stable(feature = "rust1", since = "1.0.0")]
450-
pub fn as_ref(&self) -> Result<&T, &E> {
453+
pub const fn as_ref(&self) -> Result<&T, &E> {
451454
match *self {
452455
Ok(ref x) => Ok(x),
453456
Err(ref x) => Err(x),

0 commit comments

Comments
 (0)