File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ declare_clippy_lint! {
18
18
/// ### What it does
19
19
/// Checks for calls to `push` immediately after creating a new `Vec`.
20
20
///
21
+ /// If the `Vec` is created using `with_capacity` this will only lint if the capacity is a
22
+ /// constant and the number of pushes is greater than or equal to the initial capacity.
23
+ ///
24
+ /// If the `Vec` is extended after the initial sequence of pushes and it was default initialized
25
+ /// then this will only lint after there were at least four pushes. This number may change in
26
+ /// the future.
27
+ ///
21
28
/// ### Why is this bad?
22
29
/// The `vec![]` macro is both more performant and easier to read than
23
30
/// multiple `push` calls.
@@ -56,7 +63,7 @@ struct VecPushSearcher {
56
63
}
57
64
impl VecPushSearcher {
58
65
fn display_err ( & self , cx : & LateContext < ' _ > ) {
59
- let min_pushes_for_extension = match self . init {
66
+ let required_pushes_before_extension = match self . init {
60
67
_ if self . found == 0 => return ,
61
68
VecInitKind :: WithConstCapacity ( x) if x > self . found => return ,
62
69
VecInitKind :: WithConstCapacity ( x) => x,
@@ -110,7 +117,7 @@ impl VecPushSearcher {
110
117
} ) ;
111
118
112
119
// Avoid allocating small `Vec`s when they'll be extended right after.
113
- if res == ControlFlow :: Break ( true ) && self . found <= min_pushes_for_extension {
120
+ if res == ControlFlow :: Break ( true ) && self . found <= required_pushes_before_extension {
114
121
return ;
115
122
}
116
123
You can’t perform that action at this time.
0 commit comments