]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/vec_init_then_push.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / vec_init_then_push.txt
1 ### What it does
2 Checks for calls to `push` immediately after creating a new `Vec`.
3
4 If the `Vec` is created using `with_capacity` this will only lint if the capacity is a
5 constant and the number of pushes is greater than or equal to the initial capacity.
6
7 If the `Vec` is extended after the initial sequence of pushes and it was default initialized
8 then this will only lint after there were at least four pushes. This number may change in
9 the future.
10
11 ### Why is this bad?
12 The `vec![]` macro is both more performant and easier to read than
13 multiple `push` calls.
14
15 ### Example
16 ```
17 let mut v = Vec::new();
18 v.push(0);
19 ```
20 Use instead:
21 ```
22 let v = vec![0];
23 ```