Skip to content

Commit a446b68

Browse files
committed
Add @thestinger comment explaining that shrink_to_fit might drop down as close as possible but not to the minimun
1 parent fe6847a commit a446b68

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libcollections/vec.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,9 @@ impl<T> Vec<T> {
636636
}
637637
}
638638

639-
/// Shrinks the capacity of the vector as much as possible.
639+
/// Shrinks the capacity of the vector as much as possible. It will drop
640+
/// down as close as possible to the length but the allocator may still
641+
/// inform the vector that there is space for a few more elements.
640642
///
641643
/// # Example
642644
///
@@ -645,7 +647,7 @@ impl<T> Vec<T> {
645647
/// vec.push_all([1, 2, 3]);
646648
/// assert_eq!(vec.capacity(), 10);
647649
/// vec.shrink_to_fit();
648-
/// assert_eq!(vec.capacity(), 3);
650+
/// assert!(vec.capacity() >= 3);
649651
/// ```
650652
#[stable]
651653
pub fn shrink_to_fit(&mut self) {

0 commit comments

Comments
 (0)