Skip to content

Commit

Permalink
Stabilize some Option methods as const
Browse files Browse the repository at this point in the history
Stabilize the following methods of `Option` as const:
 - `is_some`
 - `is_none`
 - `as_ref`

Possible because of stabilization of #49146 (Allow if and match in constants).
  • Loading branch information
CDirkx authored and CDirkx committed Sep 20, 2020
1 parent 81e0270 commit 9486f72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 3 additions & 3 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<T> Option<T> {
/// ```
#[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"]
#[inline]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn is_some(&self) -> bool {
matches!(*self, Some(_))
Expand All @@ -195,7 +195,7 @@ impl<T> Option<T> {
#[must_use = "if you intended to assert that this doesn't have a value, consider \
`.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"]
#[inline]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn is_none(&self) -> bool {
!self.is_some()
Expand Down Expand Up @@ -254,7 +254,7 @@ impl<T> Option<T> {
/// println!("still can print text: {:?}", text);
/// ```
#[inline]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn as_ref(&self) -> Option<&T> {
match *self {
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/consts/const-option.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// run-pass

#![feature(const_option)]

const X: Option<i32> = Some(32);
const Y: Option<&i32> = X.as_ref();

Expand Down

0 comments on commit 9486f72

Please sign in to comment.