File tree Expand file tree Collapse file tree 1 file changed +4
-12
lines changed Expand file tree Collapse file tree 1 file changed +4
-12
lines changed Original file line number Diff line number Diff line change @@ -29,26 +29,18 @@ declare_clippy_lint! {
2929 /// it involves two operations for allocating and initializing.
3030 /// The `resize` call first allocates memory (since `Vec::new()` did not), and only *then* zero-initializes it.
3131 ///
32- /// Writing `Vec::with_capacity(size)` followed by `vec.resize(len, 0)` is similar.
33- /// The allocation shifts from `resize` to `with_capacity`,
34- /// but the zero-initialization still happens separately,
35- /// when it could be done in one call with `vec![0; len]` (`alloc_zeroed`).
36- ///
3732 /// ### Example
3833 /// ```rust
3934 /// # use core::iter::repeat;
4035 /// # let len = 4;
41- /// let mut vec1 = Vec::with_capacity(len );
36+ /// let mut vec1 = Vec::new( );
4237 /// vec1.resize(len, 0);
4338 ///
44- /// let mut vec1 = Vec::with_capacity(len);
45- /// vec1.resize(vec1.capacity(), 0);
46- ///
4739 /// let mut vec2 = Vec::with_capacity(len);
48- /// vec2.extend(repeat(0).take( len) );
40+ /// vec2.resize( len, 0 );
4941 ///
50- /// let mut vec3 = Vec::new( );
51- /// vec3.resize(len, 0 );
42+ /// let mut vec3 = Vec::with_capacity(len );
43+ /// vec3.extend(repeat(0).take(len) );
5244 /// ```
5345 ///
5446 /// Use instead:
You can’t perform that action at this time.
0 commit comments