about summary refs log tree commit diff
path: root/library/alloc/src/vec/mod.rs
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2021-09-28 16:27:47 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2021-09-28 16:27:47 -0700
commit1fca2ce9010a581798fa39d1742eddcaada359ad (patch)
tree7b041c0e9f711a0a0fa54fdc438b1ceed232bf66 /library/alloc/src/vec/mod.rs
parent58b1a127d66b71e1a2180b509856f2c52feca9b3 (diff)
downloadrust-1fca2ce9010a581798fa39d1742eddcaada359ad.tar.gz
rust-1fca2ce9010a581798fa39d1742eddcaada359ad.zip
Additional docs about Vec::leak behavior
Diffstat (limited to 'library/alloc/src/vec/mod.rs')
-rw-r--r--library/alloc/src/vec/mod.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index a8b939bc249..30cd95d6959 100644
--- a/library/alloc/src/vec/mod.rs
+++ b/library/alloc/src/vec/mod.rs
@@ -1952,8 +1952,11 @@ impl<T, A: Allocator> Vec<T, A> {
     /// `'a`. If the type has only static references, or none at all, then this
     /// may be chosen to be `'static`.
     ///
-    /// This function is similar to the [`leak`][Box::leak] function on [`Box`]
-    /// except that there is no way to recover the leaked memory.
+    /// This method does not reallocate or shrink the `Vec`, so the leaked
+    /// allocation may include unused capacity that is not part of the returned
+    /// slice.  Unsafe code that later reconstructs or deallocates the `Vec`
+    /// (for example, by calling [`Vec::from_raw_parts`]) must keep track of the
+    /// original capacity.
     ///
     /// This function is mainly useful for data that lives for the remainder of
     /// the program's life. Dropping the returned reference will cause a memory