Skip to content

Commit

Permalink
Rollup merge of rust-lang#67685 - lukaslueg:const_result, r=oli-obk
Browse files Browse the repository at this point in the history
Constify Result

r? @oli-obk

This is just the `Result`-part of rust-lang#67494 which I'll resubmit once rust-lang#66254 has landed.
  • Loading branch information
Dylan-DPC authored Dec 31, 2019
2 parents 7fce3e1 + a145b80 commit b8c59f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@
#![feature(const_if_match)]
#![feature(const_panic)]
#![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)]
Expand Down
9 changes: 6 additions & 3 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit b8c59f3

Please sign in to comment.