Skip to content

Commit 94ec421

Browse files
committed
Update vec_init_then_push docs
1 parent 948af01 commit 94ec421

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

clippy_lints/src/vec_init_then_push.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ declare_clippy_lint! {
1818
/// ### What it does
1919
/// Checks for calls to `push` immediately after creating a new `Vec`.
2020
///
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+
///
2128
/// ### Why is this bad?
2229
/// The `vec![]` macro is both more performant and easier to read than
2330
/// multiple `push` calls.
@@ -56,7 +63,7 @@ struct VecPushSearcher {
5663
}
5764
impl VecPushSearcher {
5865
fn display_err(&self, cx: &LateContext<'_>) {
59-
let min_pushes_for_extension = match self.init {
66+
let required_pushes_before_extension = match self.init {
6067
_ if self.found == 0 => return,
6168
VecInitKind::WithConstCapacity(x) if x > self.found => return,
6269
VecInitKind::WithConstCapacity(x) => x,
@@ -110,7 +117,7 @@ impl VecPushSearcher {
110117
});
111118

112119
// 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 {
114121
return;
115122
}
116123

0 commit comments

Comments
 (0)