Skip to content

Commit 0edc90c

Browse files
committed
clarify alignment requirements in Vec::from_raw_parts
1 parent b961a03 commit 0edc90c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/liballoc/vec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ impl<T> Vec<T> {
404404
///
405405
/// * `ptr` needs to have been previously allocated via [`String`]/`Vec<T>`
406406
/// (at least, it's highly likely to be incorrect if it wasn't).
407-
/// * `ptr`'s `T` needs to have the same size and alignment as it was allocated with.
407+
/// * `T` needs to have the same size and alignment as what `ptr` was allocated with.
408+
/// (`T` having a less strict alignment is not sufficient, the alignment really
409+
/// needs to be equal to satsify the [`dealloc`] requirement that memory must be
410+
/// allocated and deallocated with the same layout.)
408411
/// * `length` needs to be less than or equal to `capacity`.
409412
/// * `capacity` needs to be the capacity that the pointer was allocated with.
410413
///
@@ -423,6 +426,7 @@ impl<T> Vec<T> {
423426
/// function.
424427
///
425428
/// [`String`]: ../../std/string/struct.String.html
429+
/// [`dealloc`]: ../../alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc
426430
///
427431
/// # Examples
428432
///

0 commit comments

Comments
 (0)