Skip to content

Commit 59fe3b5

Browse files
committed
Const unwrap_or
1 parent ef55a0a commit 59fe3b5

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

library/core/src/option.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,9 @@ impl<T> Option<T> {
386386
/// assert_eq!(None.unwrap_or("bike"), "bike");
387387
/// ```
388388
#[inline]
389+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
389390
#[stable(feature = "rust1", since = "1.0.0")]
390-
pub fn unwrap_or(self, default: T) -> T {
391+
pub const fn unwrap_or(self, default: T) -> T {
391392
match self {
392393
Some(x) => x,
393394
None => default,

library/core/src/result.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,9 @@ impl<T, E> Result<T, E> {
796796
/// assert_eq!(x.unwrap_or(default), default);
797797
/// ```
798798
#[inline]
799+
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
799800
#[stable(feature = "rust1", since = "1.0.0")]
800-
pub fn unwrap_or(self, default: T) -> T {
801+
pub const fn unwrap_or(self, default: T) -> T {
801802
match self {
802803
Ok(t) => t,
803804
Err(_) => default,

0 commit comments

Comments
 (0)