about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-12-30 10:30:28 -0800
committerDavid Tolnay <dtolnay@gmail.com>2021-12-30 10:30:28 -0800
commite63e2680dadeb87c9fea78c431e628cf7ed461a6 (patch)
tree8ec3c7605510c492a79079d1b663fb45db85f6dd
parentb2df61fa9f69554f3a1cdc5e02d1259396f8ff53 (diff)
downloadrust-e63e2680dadeb87c9fea78c431e628cf7ed461a6.tar.gz
rust-e63e2680dadeb87c9fea78c431e628cf7ed461a6.zip
Consolidate impl Result<&T, E>
-rw-r--r--library/core/src/result.rs48
1 files changed, 26 insertions, 22 deletions
diff --git a/library/core/src/result.rs b/library/core/src/result.rs
index 382a5711641..29a0be68083 100644
--- a/library/core/src/result.rs
+++ b/library/core/src/result.rs
@@ -1493,7 +1493,7 @@ impl<T, E> Result<T, E> {
     }
 }
 
-impl<T: Copy, E> Result<&T, E> {
+impl<T, E> Result<&T, E> {
     /// Maps a `Result<&T, E>` to a `Result<T, E>` by copying the contents of the
     /// `Ok` part.
     ///
@@ -1508,9 +1508,33 @@ impl<T: Copy, E> Result<&T, E> {
     /// assert_eq!(copied, Ok(12));
     /// ```
     #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
-    pub fn copied(self) -> Result<T, E> {
+    pub fn copied(self) -> Result<T, E>
+    where
+        T: Copy,
+    {
         self.map(|&t| t)
     }
+
+    /// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
+    /// `Ok` part.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(result_cloned)]
+    /// let val = 12;
+    /// let x: Result<&i32, i32> = Ok(&val);
+    /// assert_eq!(x, Ok(&12));
+    /// let cloned = x.cloned();
+    /// assert_eq!(cloned, Ok(12));
+    /// ```
+    #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
+    pub fn cloned(self) -> Result<T, E>
+    where
+        T: Clone,
+    {
+        self.map(|t| t.clone())
+    }
 }
 
 impl<T: Copy, E> Result<&mut T, E> {
@@ -1533,26 +1557,6 @@ impl<T: Copy, E> Result<&mut T, E> {
     }
 }
 
-impl<T: Clone, E> Result<&T, E> {
-    /// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
-    /// `Ok` part.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// #![feature(result_cloned)]
-    /// let val = 12;
-    /// let x: Result<&i32, i32> = Ok(&val);
-    /// assert_eq!(x, Ok(&12));
-    /// let cloned = x.cloned();
-    /// assert_eq!(cloned, Ok(12));
-    /// ```
-    #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
-    pub fn cloned(self) -> Result<T, E> {
-        self.map(|t| t.clone())
-    }
-}
-
 impl<T: Clone, E> Result<&mut T, E> {
     /// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
     /// `Ok` part.