Skip to content

Commit 70f1566

Browse files
Rollup merge of #106584 - kpreid:vec-allocator, r=JohnTitor
Document that `Vec::from_raw_parts[_in]` must be given a pointer from the correct allocator. Currently, the documentation of `Vec::from_raw_parts` and `Vec::from_raw_parts_in` says nothing about what allocator the pointer must come from. This PR adds that missing information explicitly.
2 parents eefc44b + 288e89b commit 70f1566

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/alloc/src/vec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ impl<T> Vec<T> {
490490
/// This is highly unsafe, due to the number of invariants that aren't
491491
/// checked:
492492
///
493+
/// * `ptr` must have been allocated using the global allocator, such as via
494+
/// the [`alloc::alloc`] function.
493495
/// * `T` needs to have the same alignment as what `ptr` was allocated with.
494496
/// (`T` having a less strict alignment is not sufficient, the alignment really
495497
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -526,6 +528,7 @@ impl<T> Vec<T> {
526528
/// function.
527529
///
528530
/// [`String`]: crate::string::String
531+
/// [`alloc::alloc`]: crate::alloc::alloc
529532
/// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
530533
///
531534
/// # Examples
@@ -681,6 +684,7 @@ impl<T, A: Allocator> Vec<T, A> {
681684
/// This is highly unsafe, due to the number of invariants that aren't
682685
/// checked:
683686
///
687+
/// * `ptr` must be [*currently allocated*] via the given allocator `alloc`.
684688
/// * `T` needs to have the same alignment as what `ptr` was allocated with.
685689
/// (`T` having a less strict alignment is not sufficient, the alignment really
686690
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
@@ -714,6 +718,7 @@ impl<T, A: Allocator> Vec<T, A> {
714718
///
715719
/// [`String`]: crate::string::String
716720
/// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
721+
/// [*currently allocated*]: crate::alloc::Allocator#currently-allocated-memory
717722
/// [*fit*]: crate::alloc::Allocator#memory-fitting
718723
///
719724
/// # Examples

0 commit comments

Comments
 (0)