From 35a9fc3472b232b924b843c468399ca44320a55d Mon Sep 17 00:00:00 2001
From: invpt <57822954+invpt@users.noreply.github.com>
Date: Thu, 18 Jan 2024 14:40:56 -0500
Subject: [PATCH] Clarify docs for Vec::into_boxed_slice, Vec::shrink_to_fit
---
library/alloc/src/vec/mod.rs | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index 8aa0c6e7ed6..35ea97bfe60 100644
--- a/library/alloc/src/vec/mod.rs
+++ b/library/alloc/src/vec/mod.rs
@@ -358,7 +358,7 @@
///
/// `vec![x; n]`, `vec![a, b, c, d]`, and
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
-/// with exactly the requested capacity. If [len] == [capacity]
,
+/// with at least the requested capacity. If [len] == [capacity]
,
/// (as is the case for the [`vec!`] macro), then a `Vec` can be converted to
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
///
@@ -1023,8 +1023,11 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
/// Shrinks the capacity of the vector as much as possible.
///
- /// It will drop down as close as possible to the length but the allocator
- /// may still inform the vector that there is space for a few more elements.
+ /// The behavior of this method depends on the allocator, which may either shrink the vector
+ /// in-place or reallocate. The resulting vector might still have some excess capacity, just as
+ /// is the case for [`with_capacity`]. See [`Allocator::shrink`] for more details.
+ ///
+ /// [`with_capacity`]: Vec::with_capacity
///
/// # Examples
///
@@ -1074,10 +1077,10 @@ pub fn shrink_to(&mut self, min_capacity: usize) {
/// Converts the vector into [`Box<[T]>`][owned slice].
///
- /// If the vector has excess capacity, its items will be moved into a
- /// newly-allocated buffer with exactly the right capacity.
+ /// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
///
/// [owned slice]: Box
+ /// [`shrink_to_fit`]: Vec::shrink_to_fit
///
/// # Examples
///
@@ -3290,8 +3293,10 @@ fn from(s: Box<[T], A>) -> Self {
impl From> for Box<[T], A> {
/// Convert a vector into a boxed slice.
///
- /// If `v` has excess capacity, its items will be moved into a
- /// newly-allocated buffer with exactly the right capacity.
+ /// Before doing the conversion, this method discards excess capacity like [`Vec::shrink_to_fit`].
+ ///
+ /// [owned slice]: Box
+ /// [`Vec::shrink_to_fit`]: Vec::shrink_to_fit
///
/// # Examples
///