Simplified code and added tests
This commit is contained in:
parent
a1bf23f0a3
commit
b0bd6219c8
4 changed files with 66 additions and 120 deletions
|
|
@ -1,5 +1,17 @@
|
|||
#![warn(clippy::reserve_after_initialization)]
|
||||
|
||||
fn main() {
|
||||
let v: Vec<usize> = Vec::with_capacity(10);
|
||||
// Should lint
|
||||
let mut v1: Vec<usize> = Vec::with_capacity(10);
|
||||
|
||||
// Should lint
|
||||
let capacity = 10;
|
||||
let mut v2: Vec<usize> = Vec::with_capacity(capacity);
|
||||
|
||||
// Shouldn't lint
|
||||
let mut v3 = vec![1];
|
||||
v3.reserve(10);
|
||||
|
||||
// Shouldn't lint
|
||||
let mut v4: Vec<usize> = Vec::with_capacity(10);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,19 @@
|
|||
#![warn(clippy::reserve_after_initialization)]
|
||||
|
||||
fn main() {
|
||||
let mut v: Vec<usize> = vec![];
|
||||
v.reserve(10);
|
||||
// Should lint
|
||||
let mut v1: Vec<usize> = vec![];
|
||||
v1.reserve(10);
|
||||
|
||||
// Should lint
|
||||
let capacity = 10;
|
||||
let mut v2: Vec<usize> = vec![];
|
||||
v2.reserve(capacity);
|
||||
|
||||
// Shouldn't lint
|
||||
let mut v3 = vec![1];
|
||||
v3.reserve(10);
|
||||
|
||||
// Shouldn't lint
|
||||
let mut v4: Vec<usize> = Vec::with_capacity(10);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,18 @@
|
|||
error: calls to `reverse` immediately after creation
|
||||
--> $DIR/reserve_after_initialization.rs:4:5
|
||||
--> $DIR/reserve_after_initialization.rs:5: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);`
|
||||
LL | / let mut v1: Vec<usize> = vec![];
|
||||
LL | | v1.reserve(10);
|
||||
| |___________________^ help: consider using `Vec::with_capacity(space_hint)`: `let mut v1: Vec<usize> = Vec::with_capacity(10);`
|
||||
|
|
||||
= note: `-D clippy::reserve-after-initialization` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
error: calls to `reverse` immediately after creation
|
||||
--> $DIR/reserve_after_initialization.rs:10:5
|
||||
|
|
||||
LL | / let mut v2: Vec<usize> = vec![];
|
||||
LL | | v2.reserve(capacity);
|
||||
| |_________________________^ help: consider using `Vec::with_capacity(space_hint)`: `let mut v2: Vec<usize> = Vec::with_capacity(capacity);`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue