diff options
| author | bors <bors@rust-lang.org> | 2017-04-20 06:28:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-04-20 06:28:16 +0000 |
| commit | fa6b50fc6282a2c64814b35b16464a22f4ae9265 (patch) | |
| tree | 3c2914f8b96d35eed2b3cbe0a27bc7b89be4272e /src/libstd | |
| parent | 1bb1530239c801bb46b705eb2874ac4e5b213e54 (diff) | |
| parent | 204243fcac7dfb646c37cab0138fc037dcb0bd53 (diff) | |
| download | rust-fa6b50fc6282a2c64814b35b16464a22f4ae9265.tar.gz rust-fa6b50fc6282a2c64814b35b16464a22f4ae9265.zip | |
Auto merge of #41413 - frewsxcv:rollup, r=frewsxcv
Rollup of 5 pull requests - Successful merges: #41214, #41369, #41377, #41378, #41390 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 18 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/path.rs | 12 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index bf3f41b13c1..b90192dd8af 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -677,7 +677,13 @@ impl Borrow<OsStr> for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl ToOwned for OsStr { type Owned = OsString; - fn to_owned(&self) -> OsString { self.to_os_string() } + fn to_owned(&self) -> OsString { + self.to_os_string() + } + fn clone_into(&self, target: &mut OsString) { + target.clear(); + target.push(self); + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -863,4 +869,14 @@ mod tests { let boxed = <Box<OsStr>>::default(); assert!(boxed.is_empty()); } + + #[test] + fn test_os_str_clone_into() { + let mut os_string = OsString::with_capacity(123); + os_string.push("hello"); + let os_str = OsStr::new("bonjour"); + os_str.clone_into(&mut os_string); + assert_eq!(os_str, os_string); + assert!(os_string.capacity() >= 123); + } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8de6e1a24f1..367779bb701 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -311,6 +311,7 @@ #![feature(str_utf16)] #![feature(test, rustc_private)] #![feature(thread_local)] +#![feature(toowned_clone_into)] #![feature(try_from)] #![feature(unboxed_closures)] #![feature(unicode)] 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); + } } |
