diff options
Diffstat (limited to 'library/std/src/ffi/os_str/tests.rs')
| -rw-r--r-- | library/std/src/ffi/os_str/tests.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/library/std/src/ffi/os_str/tests.rs b/library/std/src/ffi/os_str/tests.rs index 5b39b9e34d8..67147934b4d 100644 --- a/library/std/src/ffi/os_str/tests.rs +++ b/library/std/src/ffi/os_str/tests.rs @@ -1,4 +1,6 @@ use super::*; +use crate::mem::MaybeUninit; +use crate::ptr; #[test] fn test_os_string_with_capacity() { @@ -286,3 +288,18 @@ fn slice_surrogate_edge() { assert_eq!(post_crab.slice_encoded_bytes(..4), "🦀"); assert_eq!(post_crab.slice_encoded_bytes(4..), surrogate); } + +#[test] +fn clone_to_uninit() { + let a = OsStr::new("hello.txt"); + + let mut storage = vec![MaybeUninit::<u8>::uninit(); size_of_val::<OsStr>(a)]; + unsafe { a.clone_to_uninit(ptr::from_mut::<[_]>(storage.as_mut_slice()) as *mut OsStr) }; + assert_eq!(a.as_encoded_bytes(), unsafe { MaybeUninit::slice_assume_init_ref(&storage) }); + + let mut b: Box<OsStr> = OsStr::new("world.exe").into(); + assert_eq!(size_of_val::<OsStr>(a), size_of_val::<OsStr>(&b)); + assert_ne!(a, &*b); + unsafe { a.clone_to_uninit(ptr::from_mut::<OsStr>(&mut b)) }; + assert_eq!(a, &*b); +} |
