Skip to content

Commit 9a778bc

Browse files
committed
auto merge of #18254 : areski/rust/pr-fix-vec-doc-example, r=alexcrichton
- shrink_to_fit example is now more clear by asserting the capacity value - annotation [0, mid) changed for [0, mid]
2 parents faed648 + a446b68 commit 9a778bc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libcollections/vec.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,18 @@ 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
///
643645
/// ```
644-
/// let mut vec = vec![1i, 2, 3];
646+
/// let mut vec: Vec<int> = Vec::with_capacity(10);
647+
/// vec.push_all([1, 2, 3]);
648+
/// assert_eq!(vec.capacity(), 10);
645649
/// vec.shrink_to_fit();
650+
/// assert!(vec.capacity() >= 3);
646651
/// ```
647652
#[stable]
648653
pub fn shrink_to_fit(&mut self) {
@@ -830,6 +835,7 @@ impl<T> Vec<T> {
830835
/// for num in vec.iter_mut() {
831836
/// *num = 0;
832837
/// }
838+
/// assert_eq!(vec, vec![0i, 0, 0]);
833839
/// ```
834840
#[inline]
835841
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a,T> {

0 commit comments

Comments
 (0)