Skip to content

Commit a145b80

Browse files
committed
Constify Result
1 parent 41501a6 commit a145b80

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/libcore/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@
7272
#![feature(concat_idents)]
7373
#![feature(const_fn)]
7474
#![feature(const_fn_union)]
75+
#![feature(const_if_match)]
7576
#![feature(const_generics)]
7677
#![feature(const_ptr_offset_from)]
78+
#![feature(const_result)]
7779
#![feature(const_type_name)]
7880
#![feature(custom_inner_attributes)]
7981
#![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)