Skip to content

Commit 52c28ff

Browse files
committed
Clarify vec docs on deallocation (fixes #46879)
1 parent df8dfde commit 52c28ff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/liballoc/vec.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@ use Bound::{Excluded, Included, Unbounded};
224224
/// types inside a `Vec`, it will not allocate space for them. *Note that in this case
225225
/// the `Vec` may not report a [`capacity`] of 0*. `Vec` will allocate if and only
226226
/// if [`mem::size_of::<T>`]`() * capacity() > 0`. In general, `Vec`'s allocation
227-
/// details are subtle enough that it is strongly recommended that you only
228-
/// free memory allocated by a `Vec` by creating a new `Vec` and dropping it.
227+
/// details are very subtle &mdash; if you intend to allocate memory using a `Vec`
228+
/// and use it for something else (either to pass to unsafe code, or to build your
229+
/// own memory-backed collection), be sure to deallocate this memory by using
230+
/// `from_raw_parts` to recover the `Vec` and then dropping it.
229231
///
230232
/// If a `Vec` *has* allocated memory, then the memory it points to is on the heap
231233
/// (as defined by the allocator Rust is configured to use by default), and its

0 commit comments

Comments
 (0)