Skip to content

Commit 50ca3ac

Browse files
committed
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.
2 parents ca075d2 + 4a8671a commit 50ca3ac

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

library/std/src/ffi/os_str.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
7171
/// [`&str`]: str
7272
/// [`CStr`]: crate::ffi::CStr
7373
/// [conversions]: super#conversions
74-
#[derive(Clone)]
7574
#[cfg_attr(not(test), rustc_diagnostic_item = "OsString")]
7675
#[stable(feature = "rust1", since = "1.0.0")]
7776
pub struct OsString {
@@ -420,6 +419,19 @@ impl Default for OsString {
420419
}
421420
}
422421

422+
#[stable(feature = "rust1", since = "1.0.0")]
423+
impl Clone for OsString {
424+
#[inline]
425+
fn clone(&self) -> Self {
426+
OsString { inner: self.inner.clone() }
427+
}
428+
429+
#[inline]
430+
fn clone_from(&mut self, source: &Self) {
431+
self.inner.clone_from(&source.inner)
432+
}
433+
}
434+
423435
#[stable(feature = "rust1", since = "1.0.0")]
424436
impl fmt::Debug for OsString {
425437
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {

library/std/src/path.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,6 @@ impl FusedIterator for Ancestors<'_> {}
10651065
/// ```
10661066
///
10671067
/// Which method works best depends on what kind of situation you're in.
1068-
#[derive(Clone)]
10691068
#[cfg_attr(not(test), rustc_diagnostic_item = "PathBuf")]
10701069
#[stable(feature = "rust1", since = "1.0.0")]
10711070
// FIXME:
@@ -1406,6 +1405,19 @@ impl PathBuf {
14061405
}
14071406
}
14081407

1408+
#[stable(feature = "rust1", since = "1.0.0")]
1409+
impl Clone for PathBuf {
1410+
#[inline]
1411+
fn clone(&self) -> Self {
1412+
PathBuf { inner: self.inner.clone() }
1413+
}
1414+
1415+
#[inline]
1416+
fn clone_from(&mut self, source: &Self) {
1417+
self.inner.clone_from(&source.inner)
1418+
}
1419+
}
1420+
14091421
#[stable(feature = "box_from_path", since = "1.17.0")]
14101422
impl From<&Path> for Box<Path> {
14111423
fn from(path: &Path) -> Box<Path> {

library/std/src/sys_common/os_str_bytes.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
1414

1515
use core::str::lossy::Utf8Lossy;
1616

17-
#[derive(Clone, Hash)]
17+
#[derive(Hash)]
1818
pub(crate) struct Buf {
1919
pub inner: Vec<u8>,
2020
}
@@ -53,6 +53,18 @@ impl fmt::Display for Buf {
5353
}
5454
}
5555

56+
impl Clone for Buf {
57+
#[inline]
58+
fn clone(&self) -> Self {
59+
Buf { inner: self.inner.clone() }
60+
}
61+
62+
#[inline]
63+
fn clone_from(&mut self, source: &Self) {
64+
self.inner.clone_from(&source.inner)
65+
}
66+
}
67+
5668
impl IntoInner<Vec<u8>> for Buf {
5769
fn into_inner(self) -> Vec<u8> {
5870
self.inner

0 commit comments

Comments
 (0)