fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

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