about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2024-09-08 09:24:06 +0200
committerRalf Jung <post@ralfj.de>2024-09-08 16:52:40 +0200
commitf7b4f4a73bcaa2987fddfa86c240a497780c88c8 (patch)
treee6c61fab35d0e3cec861492ca460250c70b4047d
parent3de6838238dd72004acf0e6b3f158837952c1dc3 (diff)
downloadrust-f7b4f4a73bcaa2987fddfa86c240a497780c88c8.tar.gz
rust-f7b4f4a73bcaa2987fddfa86c240a497780c88c8.zip
Option, Result: put the &mut variants of 'copied' under the same feature as the '&' variants
-rw-r--r--library/core/src/option.rs2
-rw-r--r--library/core/src/result.rs10
2 files changed, 9 insertions, 3 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index b62eec1897b..80598b88529 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -1942,7 +1942,7 @@ impl<T> Option<&mut T> {
     /// ```
     #[must_use = "`self` will be dropped if the result is not used"]
     #[stable(feature = "copied", since = "1.35.0")]
-    #[rustc_const_unstable(feature = "const_option_ext", issue = "91930")]
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
     pub const fn copied(self) -> Option<T>
     where
         T: Copy,
diff --git a/library/core/src/result.rs b/library/core/src/result.rs
index 5b6a81c8dae..02f6f783b51 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -1585,11 +1585,17 @@ impl<T, E> Result<&mut 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(|&mut t| t)
+        // FIXME(const-hack): 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(&mut v) => Ok(v),
+            Err(e) => Err(e),
+        }
     }
 
     /// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the