]> git.lizzy.rs Git - rust.git/commitdiff
clarify alignment requirements in Vec::from_raw_parts
authorRalf Jung <post@ralfj.de>
Sat, 29 Feb 2020 13:07:20 +0000 (14:07 +0100)
committerRalf Jung <post@ralfj.de>
Sat, 29 Feb 2020 13:07:20 +0000 (14:07 +0100)
src/liballoc/vec.rs

index 29987ac44e6f9db2037392a817cb3194f7ce01b2..fc50d06b33c579c062e5b44b3e48a608bb65cabf 100644 (file)
@@ -404,7 +404,10 @@ pub fn into_raw_parts(self) -> (*mut T, usize, usize) {
     ///
     /// * `ptr` needs to have been previously allocated via [`String`]/`Vec<T>`
     ///   (at least, it's highly likely to be incorrect if it wasn't).
-    /// * `ptr`'s `T` needs to have the same size and alignment as it was allocated with.
+    /// * `T` needs to have the same size and alignment as what `ptr` was allocated with.
+    ///   (`T` having a less strict alignment is not sufficient, the alignment really
+    ///   needs to be equal to satsify the [`dealloc`] requirement that memory must be
+    ///   allocated and deallocated with the same layout.)
     /// * `length` needs to be less than or equal to `capacity`.
     /// * `capacity` needs to be the capacity that the pointer was allocated with.
     ///
@@ -423,6 +426,7 @@ pub fn into_raw_parts(self) -> (*mut T, usize, usize) {
     /// function.
     ///
     /// [`String`]: ../../std/string/struct.String.html
+    /// [`dealloc`]: ../../alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc
     ///
     /// # Examples
     ///