about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee <workingjubilee@gmail.com>2024-09-09 00:17:50 -0700
committerGitHub <noreply@github.com>2024-09-09 00:17:50 -0700
commit4a26f3b0ba70126fdd2e794c7c6cbb48bbf90ac3 (patch)
tree474ba6f65bf4f0041eb5adad1bbc81fa2097f0f1
parent38520aed189fb7d62555b80e6213f41bccd4a3cd (diff)
parentf7b4f4a73bcaa2987fddfa86c240a497780c88c8 (diff)
downloadrust-4a26f3b0ba70126fdd2e794c7c6cbb48bbf90ac3.tar.gz
rust-4a26f3b0ba70126fdd2e794c7c6cbb48bbf90ac3.zip
Rollup merge of #130090 - RalfJung:result-copied, r=Noratrieb
make Result::copied unstably const

The corresponding `Option::copied` is unstably const, so seems reasonable to do the same here.
-rw-r--r--library/core/src/option.rs4
-rw-r--r--library/core/src/result.rs20
2 files changed, 18 insertions, 6 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index 56787615e28..ff48575e2c0 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -1893,7 +1893,7 @@ impl<T> Option<&T> {
     where
         T: Copy,
     {
-        // FIXME: this implementation, which sidesteps using `Option::map` since it's not const
+        // FIXME(const-hack): this implementation, which sidesteps using `Option::map` since it's not const
         // ready yet, should be reverted when possible to avoid code repetition
         match self {
             Some(&v) => Some(v),
@@ -1941,7 +1941,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 73b11f803d9..02f6f783b51 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(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(&v) => Ok(v),
+            Err(e) => Err(e),
+        }
     }
 
     /// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
@@ -1579,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