diff options
| author | Jake Goulding <jake.goulding@gmail.com> | 2019-10-22 15:40:22 -0400 |
|---|---|---|
| committer | Jake Goulding <jake.goulding@gmail.com> | 2019-10-25 11:22:53 -0400 |
| commit | dce8fabc62ed393152c53c65c492c8f3ae324eda (patch) | |
| tree | 213b7603a91b180da60b90055a792bde8bb2b382 /src/liballoc/vec.rs | |
| parent | 0d21d257c9691983fd51e7d5d9ace4de8933114c (diff) | |
| download | rust-dce8fabc62ed393152c53c65c492c8f3ae324eda.tar.gz rust-dce8fabc62ed393152c53c65c492c8f3ae324eda.zip | |
Use ManuallyDrop in examples for {Vec,String}::from_raw_parts
Diffstat (limited to 'src/liballoc/vec.rs')
| -rw-r--r-- | src/liballoc/vec.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 6350b189c5f..c8fb8971234 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -389,7 +389,11 @@ impl<T> Vec<T> { /// use std::ptr; /// use std::mem; /// - /// let mut v = vec![1, 2, 3]; + /// let v = vec![1, 2, 3]; + /// + /// // Prevent running `v`'s destructor so we are in complete control + /// // of the allocation. + /// let mut v = mem::ManuallyDrop::new(v); /// /// // Pull out the various important pieces of information about `v` /// let p = v.as_mut_ptr(); @@ -397,10 +401,6 @@ impl<T> Vec<T> { /// let cap = v.capacity(); /// /// unsafe { - /// // Cast `v` into the void: no destructor run, so we are in - /// // complete control of the allocation to which `p` points. - /// mem::forget(v); - /// /// // Overwrite memory with 4, 5, 6 /// for i in 0..len as isize { /// ptr::write(p.offset(i), 4 + i); |
