Added new lint: reserve_after_initialization

This commit is contained in:
Red Rapious 2023-08-21 18:50:53 +02:00
parent fc1152abf6
commit 7fbf808a50
7 changed files with 268 additions and 0 deletions

View file

@ -0,0 +1,5 @@
#![warn(clippy::reserve_after_initialization)]
fn main() {
let v: Vec<usize> = Vec::with_capacity(10);
}

View file

@ -0,0 +1,6 @@
#![warn(clippy::reserve_after_initialization)]
fn main() {
let mut v: Vec<usize> = vec![];
v.reserve(10);
}

View file

@ -0,0 +1,11 @@
error: calls to `reverse` immediately after creation
--> $DIR/reserve_after_initialization.rs:4:5
|
LL | / let mut v: Vec<usize> = vec![];
LL | | v.reserve(10);
| |__________________^ help: consider using `Vec::with_capacity(space_hint)`: `let v: Vec<usize> = Vec::with_capacity(10);`
|
= note: `-D clippy::reserve-after-initialization` implied by `-D warnings`
error: aborting due to previous error