diff options
| author | Pavel Grigorenko <GrigorenkoPV@ya.ru> | 2024-06-23 23:05:10 +0300 |
|---|---|---|
| committer | Pavel Grigorenko <GrigorenkoPV@ya.ru> | 2024-07-29 20:44:39 +0300 |
| commit | afabc583f7f646d45f506263a1c331383ebdc252 (patch) | |
| tree | df95c9b8b394722c04dd8c6e865c8275e946f0ad /library/std/src/path/tests.rs | |
| parent | ec921db289ea87fd4030cb7f8a70f6ba3a31c2c7 (diff) | |
| download | rust-afabc583f7f646d45f506263a1c331383ebdc252.tar.gz rust-afabc583f7f646d45f506263a1c331383ebdc252.zip | |
impl CloneToUninit for Path and OsStr
Diffstat (limited to 'library/std/src/path/tests.rs')
| -rw-r--r-- | library/std/src/path/tests.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index a12e42cba0c..6436872087d 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -3,6 +3,8 @@ use core::hint::black_box; use super::*; use crate::collections::{BTreeSet, HashSet}; use crate::hash::DefaultHasher; +use crate::mem::MaybeUninit; +use crate::ptr; #[allow(unknown_lints, unused_macro_rules)] macro_rules! t ( @@ -2054,3 +2056,20 @@ fn bench_hash_path_long(b: &mut test::Bencher) { black_box(hasher.finish()); } + +#[test] +fn clone_to_uninit() { + let a = Path::new("hello.txt"); + + let mut storage = vec![MaybeUninit::<u8>::uninit(); size_of_val::<Path>(a)]; + unsafe { a.clone_to_uninit(ptr::from_mut::<[_]>(storage.as_mut_slice()) as *mut Path) }; + assert_eq!(a.as_os_str().as_encoded_bytes(), unsafe { + MaybeUninit::slice_assume_init_ref(&storage) + }); + + let mut b: Box<Path> = Path::new("world.exe").into(); + assert_eq!(size_of_val::<Path>(a), size_of_val::<Path>(&b)); + assert_ne!(a, &*b); + unsafe { a.clone_to_uninit(ptr::from_mut::<Path>(&mut b)) }; + assert_eq!(a, &*b); +} |
