about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2017-04-13 02:48:46 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2017-04-18 21:02:18 -0700
commit295bcdb715871ef3ba0258c75dad885b7315a162 (patch)
tree55cd65b380897d4c742b5b1073da93fd3a1cf5da /src/libstd/path.rs
parent9f2abadca2d065bf81772cb84981d0a22d8e98b3 (diff)
downloadrust-295bcdb715871ef3ba0258c75dad885b7315a162.tar.gz
rust-295bcdb715871ef3ba0258c75dad885b7315a162.zip
Override ToOwned::clone_into for Path and OsStr
The only non-overridden one remaining is the CStr impl, which cannot
be optimized as doing so would break CString's second invariant.
Diffstat (limited to 'src/libstd/path.rs')
-rw-r--r--src/libstd/path.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index db446d88900..fcbd3705e88 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -1322,6 +1322,9 @@ impl ToOwned for Path {
     fn to_owned(&self) -> PathBuf {
         self.to_path_buf()
     }
+    fn clone_into(&self, target: &mut PathBuf) {
+        self.inner.clone_into(&mut target.inner);
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -3722,4 +3725,13 @@ mod tests {
         assert_eq!(&*boxed, &*path_buf);
         assert_eq!(&*path_buf, path);
     }
+
+    #[test]
+    fn test_clone_into() {
+        let mut path_buf = PathBuf::from("supercalifragilisticexpialidocious");
+        let path = Path::new("short");
+        path.clone_into(&mut path_buf);
+        assert_eq!(path, path_buf);
+        assert!(path_buf.into_os_string().capacity() >= 15);
+    }
 }