@@ -84,7 +84,7 @@ pub use crate::intrinsics::transmute;
8484///
8585/// let mut v = vec![65, 122];
8686/// // Build a `String` using the contents of `v`
87- /// let s = unsafe { String::from_raw_parts(v.as_mut_ptr(), 2 , v.capacity()) };
87+ /// let s = unsafe { String::from_raw_parts(v.as_mut_ptr(), v.len() , v.capacity()) };
8888/// // leak `v` because its memory is now managed by `s`
8989/// mem::forget(v); // ERROR - v is invalid and must not be passed to a function
9090/// assert_eq!(s, "Az");
@@ -113,10 +113,9 @@ pub use crate::intrinsics::transmute;
113113/// // does not get dropped!
114114/// let mut v = ManuallyDrop::new(v);
115115/// // Now disassemble `v`. These operations cannot panic, so there cannot be a leak.
116- /// let ptr = v.as_mut_ptr();
117- /// let cap = v.capacity();
116+ /// let (ptr, len, cap) = (v.as_mut_ptr(), v.len(), v.capacity());
118117/// // Finally, build a `String`.
119- /// let s = unsafe { String::from_raw_parts(ptr, 2 , cap) };
118+ /// let s = unsafe { String::from_raw_parts(ptr, len , cap) };
120119/// assert_eq!(s, "Az");
121120/// // `s` is implicitly dropped and its memory deallocated.
122121/// ```
0 commit comments