Skip to content

Commit 72723d7

Browse files
committed
make Result::copied unstably const
1 parent fee6300 commit 72723d7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/src/result.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1535,11 +1535,17 @@ impl<T, E> Result<&T, E> {
15351535
/// ```
15361536
#[inline]
15371537
#[stable(feature = "result_copied", since = "1.59.0")]
1538-
pub fn copied(self) -> Result<T, E>
1538+
#[rustc_const_unstable(feature = "const_result", issue = "82814")]
1539+
pub const fn copied(self) -> Result<T, E>
15391540
where
15401541
T: Copy,
15411542
{
1542-
self.map(|&t| t)
1543+
// FIXME: this implementation, which sidesteps using `Result::map` since it's not const
1544+
// ready yet, should be reverted when possible to avoid code repetition
1545+
match self {
1546+
Ok(&v) => Ok(v),
1547+
Err(e) => Err(e),
1548+
}
15431549
}
15441550

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

0 commit comments

Comments
 (0)