blob: b57a8e162c53957b6b03e56d2c50e65e0564fc99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
//@aux-build:proc_macros.rs
#![warn(clippy::reserve_after_initialization)]
#![no_main]
extern crate proc_macros;
use proc_macros::{external, with_span};
// Should lint
fn standard() {
let mut v1: Vec<usize> = vec![];
v1.reserve(10);
}
// Should lint
fn capacity_as_expr() {
let capacity = 10;
let mut v2: Vec<usize> = vec![];
v2.reserve(capacity);
}
// Shouldn't lint
fn vec_init_with_argument() {
let mut v3 = vec![1];
v3.reserve(10);
}
// Shouldn't lint
fn called_with_capacity() {
let _v4: Vec<usize> = Vec::with_capacity(10);
}
// Should lint
fn assign_expression() {
let mut v5: Vec<usize> = Vec::new();
v5 = Vec::new();
v5.reserve(10);
}
fn in_macros() {
external! {
let mut v: Vec<usize> = vec![];
v.reserve(10);
}
with_span! {
span
let mut v: Vec<usize> = vec![];
v.reserve(10);
}
}
|