about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-28 23:25:23 +0000
committerbors <bors@rust-lang.org>2021-04-28 23:25:23 +0000
commit50ca3ac24f08cc6c8bbef9ac27245f83f30bc749 (patch)
tree1d98d5d8b725d8ab9c60122d30e3a9b33da33e48
parentca075d268d2ce315964e1dd195cfe837b8a53f4d (diff)
parent4a8671a2fa89bfcb925cd9a8e7c5887387cc59ab (diff)
downloadrust-50ca3ac24f08cc6c8bbef9ac27245f83f30bc749.tar.gz
rust-50ca3ac24f08cc6c8bbef9ac27245f83f30bc749.zip
Auto merge of #84615 - a1phyr:clone_from_pathbuf_osstring, r=Mark-Simulacrum
Override `clone_from` method for PathBuf and OsString

This was not the case before because `#[derive(Clone)]` do not do it.
-rw-r--r--library/std/src/ffi/os_str.rs14
-rw-r--r--library/std/src/path.rs14
-rw-r--r--library/std/src/sys_common/os_str_bytes.rs14
3 files changed, 39 insertions, 3 deletions
diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs
index ecaab670349..ea4b2866017 100644
--- a/library/std/src/ffi/os_str.rs
+++ b/library/std/src/ffi/os_str.rs
@@ -71,7 +71,6 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
 /// [`&str`]: str
 /// [`CStr`]: crate::ffi::CStr
 /// [conversions]: super#conversions
-#[derive(Clone)]
 #[cfg_attr(not(test), rustc_diagnostic_item = "OsString")]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct OsString {
@@ -421,6 +420,19 @@ impl Default for OsString {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+impl Clone for OsString {
+    #[inline]
+    fn clone(&self) -> Self {
+        OsString { inner: self.inner.clone() }
+    }
+
+    #[inline]
+    fn clone_from(&mut self, source: &Self) {
+        self.inner.clone_from(&source.inner)
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
 impl fmt::Debug for OsString {
     fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
         fmt::Debug::fmt(&**self, formatter)
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index f4020a42879..ed0987064e8 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -1065,7 +1065,6 @@ impl FusedIterator for Ancestors<'_> {}
 /// ```
 ///
 /// Which method works best depends on what kind of situation you're in.
-#[derive(Clone)]
 #[cfg_attr(not(test), rustc_diagnostic_item = "PathBuf")]
 #[stable(feature = "rust1", since = "1.0.0")]
 // FIXME:
@@ -1406,6 +1405,19 @@ impl PathBuf {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl Clone for PathBuf {
+    #[inline]
+    fn clone(&self) -> Self {
+        PathBuf { inner: self.inner.clone() }
+    }
+
+    #[inline]
+    fn clone_from(&mut self, source: &Self) {
+        self.inner.clone_from(&source.inner)
+    }
+}
+
 #[stable(feature = "box_from_path", since = "1.17.0")]
 impl From<&Path> for Box<Path> {
     fn from(path: &Path) -> Box<Path> {
diff --git a/library/std/src/sys_common/os_str_bytes.rs b/library/std/src/sys_common/os_str_bytes.rs
index 302c5197407..32705c432fa 100644
--- a/library/std/src/sys_common/os_str_bytes.rs
+++ b/library/std/src/sys_common/os_str_bytes.rs
@@ -14,7 +14,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
 
 use core::str::lossy::Utf8Lossy;
 
-#[derive(Clone, Hash)]
+#[derive(Hash)]
 pub(crate) struct Buf {
     pub inner: Vec<u8>,
 }
@@ -53,6 +53,18 @@ impl fmt::Display for Buf {
     }
 }
 
+impl Clone for Buf {
+    #[inline]
+    fn clone(&self) -> Self {
+        Buf { inner: self.inner.clone() }
+    }
+
+    #[inline]
+    fn clone_from(&mut self, source: &Self) {
+        self.inner.clone_from(&source.inner)
+    }
+}
+
 impl IntoInner<Vec<u8>> for Buf {
     fn into_inner(self) -> Vec<u8> {
         self.inner