Skip to content
/ rust Public
forked from rust-lang/rust

Commit dd25cc3

Browse files
committed
Remove unnecessary paragraph, move examples
1 parent d2acfb3 commit dd25cc3

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

clippy_lints/src/slow_vector_initialization.rs

+4-12
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)