about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-09-07 22:19:30 +0200
committerRalf Jung <post@ralfj.de>2024-09-07 22:23:12 +0200
commit03e0c8edb2114aaf92fb8d93a18dfb0028690765 (patch)
tree183bc991db137b10844270da249092293cc69027
parent009e73825af0e59ad4fc603562e038b3dbd6593a (diff)
downloadrust-03e0c8edb2114aaf92fb8d93a18dfb0028690765.tar.gz
rust-03e0c8edb2114aaf92fb8d93a18dfb0028690765.zip
make Result::copied unstably const
-rw-r--r--library/core/src/result.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/library/core/src/result.rs b/library/core/src/result.rs
index 73b11f803d9..a7fd95e0079 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -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