Skip to content

Commit 518f1cc

Browse files
author
CDirkx
committed
Stabilize some Result methods as const
Stabilize the following methods of `Result` as const: - `is_ok` - `is_err` - `as_ref` Possible because of stabilization of rust-lang#49146 (Allow if and match in constants).
1 parent 36b0d7e commit 518f1cc

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
#![feature(const_ptr_offset)]
8888
#![feature(const_ptr_offset_from)]
8989
#![feature(const_raw_ptr_comparison)]
90-
#![feature(const_result)]
9190
#![feature(const_slice_from_raw_parts)]
9291
#![feature(const_slice_ptr_len)]
9392
#![feature(const_size_of_val)]

library/core/src/result.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<T, E> Result<T, E> {
273273
/// assert_eq!(x.is_ok(), false);
274274
/// ```
275275
#[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
276-
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
276+
#[rustc_const_stable(feature = "const_result", since = "1.48.0")]
277277
#[inline]
278278
#[stable(feature = "rust1", since = "1.0.0")]
279279
pub const fn is_ok(&self) -> bool {
@@ -294,7 +294,7 @@ impl<T, E> Result<T, E> {
294294
/// assert_eq!(x.is_err(), true);
295295
/// ```
296296
#[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
297-
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
297+
#[rustc_const_stable(feature = "const_result", since = "1.48.0")]
298298
#[inline]
299299
#[stable(feature = "rust1", since = "1.0.0")]
300300
pub const fn is_err(&self) -> bool {
@@ -438,7 +438,7 @@ impl<T, E> Result<T, E> {
438438
/// assert_eq!(x.as_ref(), Err(&"Error"));
439439
/// ```
440440
#[inline]
441-
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
441+
#[rustc_const_stable(feature = "const_result", since = "1.48.0")]
442442
#[stable(feature = "rust1", since = "1.0.0")]
443443
pub const fn as_ref(&self) -> Result<&T, &E> {
444444
match *self {

src/test/ui/consts/const-result.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-pass
2+
3+
fn main() {
4+
const X: Result<i32, bool> = Ok(32);
5+
const Y: Result<&i32, &bool> = X.as_ref();
6+
7+
const IS_OK: bool = X.is_ok();
8+
assert!(IS_OK);
9+
10+
const IS_ERR: bool = Y.is_err();
11+
assert!(!IS_ERR)
12+
}

0 commit comments

Comments
 (0)