make Result::copied unstably const

This commit is contained in:
Ralf Jung 2024-09-07 22:19:30 +02:00
parent 009e73825a
commit 03e0c8edb2

View file

@ -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