@@ -748,10 +748,10 @@ impl<T> Vec<T> {
748
748
self
749
749
}
750
750
751
- /// Forces the length of a vector to a particular value .
751
+ /// Forces the length of the vector to `new_len` .
752
752
///
753
753
/// This is a low-level operation that maintains none of the normal
754
- /// invariants of the type. Normally changing the length of a `Vec`
754
+ /// invariants of the type. Normally changing the length of a vector
755
755
/// is done using one of the safe operations instead, such as
756
756
/// [`truncate`], [`resize`], [`extend`], or [`clear`].
757
757
///
@@ -762,14 +762,15 @@ impl<T> Vec<T> {
762
762
///
763
763
/// # Safety
764
764
///
765
- /// - `new_len` must be less than or equal to `capacity()`.
766
- /// - All elements between past the previous end up to the `new_len`
767
- /// must be initialized.
765
+ /// - `new_len` must be less than or equal to [`capacity()`].
766
+ /// - The elements at `old_len..new_len` must be initialized.
767
+ ///
768
+ /// [`capacity()`]: #method.capacity
768
769
///
769
770
/// # Examples
770
771
///
771
- /// This method can be useful for situations in which the `Vec` is
772
- /// serving as a buffer for other code, particularly over FFI:
772
+ /// This method can be useful for situations in which the vector
773
+ /// is serving as a buffer for other code, particularly over FFI:
773
774
///
774
775
/// ```no_run
775
776
/// # #![allow(dead_code)]
@@ -786,7 +787,7 @@ impl<T> Vec<T> {
786
787
/// # }
787
788
/// # impl StreamWrapper {
788
789
/// pub fn get_dictionary(&self) -> Option<Vec<u8>> {
789
- /// // Per the docs, "32768 bytes is always enough".
790
+ /// // Per the FFI method's docs, "32768 bytes is always enough".
790
791
/// let mut dict = Vec::with_capacity(32_768);
791
792
/// let mut dict_length = 0;
792
793
/// unsafe {
@@ -816,7 +817,8 @@ impl<T> Vec<T> {
816
817
/// }
817
818
/// ```
818
819
///
819
- /// (Instead, one would normally use [`clear`] in this situation.)
820
+ /// Normally, here, one would use [`clear`] instead to correctly drop
821
+ /// the contents and thus not leak memory.
820
822
#[ inline]
821
823
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
822
824
pub unsafe fn set_len ( & mut self , new_len : usize ) {
0 commit comments