about summary refs log tree commit diff
path: root/src/libstd/path.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-04-20 01:39:56 -0400
committerGitHub <noreply@github.com>2017-04-20 01:39:56 -0400
commit204243fcac7dfb646c37cab0138fc037dcb0bd53 (patch)
tree3c2914f8b96d35eed2b3cbe0a27bc7b89be4272e /src/libstd/path.rs
parent1b7e6c389828cdf1fba46f0e1892b63a260978a9 (diff)
parent295bcdb715871ef3ba0258c75dad885b7315a162 (diff)
downloadrust-204243fcac7dfb646c37cab0138fc037dcb0bd53.tar.gz
rust-204243fcac7dfb646c37cab0138fc037dcb0bd53.zip
Rollup merge of #41390 - scottmcm:toowned-clone-into, r=alexcrichton
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.

Follow-up to 7ec27ae (PR #41009).

r? @alexcrichton
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 22889b5de4c..812b65b61e7 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -1414,6 +1414,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")]
@@ -3859,4 +3862,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);
+    }
 }