about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/repeat_vec_with_capacity.fixed
blob: 8a3b0b4f193f907d9ec34064a9eaeec7366ace38 (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
#![allow(clippy::map_with_unused_argument_over_ranges)]
#![warn(clippy::repeat_vec_with_capacity)]

fn main() {
    {
        (0..123).map(|_| Vec::<()>::with_capacity(42)).collect::<Vec<_>>();
        //~^ repeat_vec_with_capacity
    }

    {
        let n = 123;
        (0..n).map(|_| Vec::<()>::with_capacity(42)).collect::<Vec<_>>();
        //~^ repeat_vec_with_capacity
    }

    {
        macro_rules! from_macro {
            ($x:expr) => {
                vec![$x; 123];
            };
        }
        // vec expansion is from another macro, don't lint
        from_macro!(Vec::<()>::with_capacity(42));
    }

    {
        std::iter::repeat_with(|| Vec::<()>::with_capacity(42));
        //~^ repeat_vec_with_capacity
    }

    {
        macro_rules! from_macro {
            ($x:expr) => {
                std::iter::repeat($x)
            };
        }
        from_macro!(Vec::<()>::with_capacity(42));
    }
}

#[clippy::msrv = "1.27.0"]
fn msrv_check() {
    std::iter::repeat(Vec::<()>::with_capacity(42));
}