Skip to content

Commit

Permalink
Const unwrap_or
Browse files Browse the repository at this point in the history
  • Loading branch information
pickfire committed Sep 5, 2020
1 parent ef55a0a commit 59fe3b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ impl<T> Option<T> {
/// assert_eq!(None.unwrap_or("bike"), "bike");
/// ```
#[inline]
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or(self, default: T) -> T {
pub const fn unwrap_or(self, default: T) -> T {
match self {
Some(x) => x,
None => default,
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,9 @@ impl<T, E> Result<T, E> {
/// assert_eq!(x.unwrap_or(default), default);
/// ```
#[inline]
#[rustc_const_unstable(feature = "const_result", issue = "67520")]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn unwrap_or(self, default: T) -> T {
pub const fn unwrap_or(self, default: T) -> T {
match self {
Ok(t) => t,
Err(_) => default,
Expand Down

0 comments on commit 59fe3b5

Please sign in to comment.