Skip to content

Commit

Permalink
make Result::copied unstably const
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 7, 2024
1 parent 009e738 commit 03e0c8e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,11 +1535,17 @@ impl<T, E> Result<&T, E> {
/// ```
#[inline]
#[stable(feature = "result_copied", since = "1.59.0")]
pub fn copied(self) -> Result<T, E>
#[rustc_const_unstable(feature = "const_result", issue = "82814")]
pub const fn copied(self) -> Result<T, E>
where
T: Copy,
{
self.map(|&t| t)
// FIXME: this implementation, which sidesteps using `Result::map` since it's not const
// ready yet, should be reverted when possible to avoid code repetition
match self {
Ok(&v) => Ok(v),
Err(e) => Err(e),
}
}

/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
Expand Down

0 comments on commit 03e0c8e

Please sign in to comment.