Skip to content

Override clone_from method for PathBuf and OsString #84615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -420,6 +419,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 {
Expand Down
14 changes: 13 additions & 1 deletion library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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> {
Expand Down
14 changes: 13 additions & 1 deletion library/std/src/sys_common/os_str_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down Expand Up @@ -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
Expand Down