Skip to content

Commit 1fca2ce

Browse files
committed
Additional docs about Vec::leak behavior
1 parent 58b1a12 commit 1fca2ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

library/alloc/src/vec/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1952,8 +1952,11 @@ impl<T, A: Allocator> Vec<T, A> {
19521952
/// `'a`. If the type has only static references, or none at all, then this
19531953
/// may be chosen to be `'static`.
19541954
///
1955-
/// This function is similar to the [`leak`][Box::leak] function on [`Box`]
1956-
/// except that there is no way to recover the leaked memory.
1955+
/// This method does not reallocate or shrink the `Vec`, so the leaked
1956+
/// allocation may include unused capacity that is not part of the returned
1957+
/// slice. Unsafe code that later reconstructs or deallocates the `Vec`
1958+
/// (for example, by calling [`Vec::from_raw_parts`]) must keep track of the
1959+
/// original capacity.
19571960
///
19581961
/// This function is mainly useful for data that lives for the remainder of
19591962
/// the program's life. Dropping the returned reference will cause a memory

0 commit comments

Comments
 (0)