]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | // run-rustfix |
2 | ||
3 | #![warn(clippy::useless_vec)] | |
4 | ||
5 | #[derive(Debug)] | |
6 | struct NonCopy; | |
7 | ||
8 | fn on_slice(_: &[u8]) {} | |
9 | #[allow(clippy::ptr_arg)] | |
10 | fn on_vec(_: &Vec<u8>) {} | |
11 | ||
12 | struct Line { | |
13 | length: usize, | |
14 | } | |
15 | ||
16 | impl Line { | |
17 | fn length(&self) -> usize { | |
18 | self.length | |
19 | } | |
20 | } | |
21 | ||
22 | fn main() { | |
23 | on_slice(&vec![]); | |
24 | on_slice(&[]); | |
25 | ||
26 | on_slice(&vec![1, 2]); | |
27 | on_slice(&[1, 2]); | |
28 | ||
29 | on_slice(&vec![1, 2]); | |
30 | on_slice(&[1, 2]); | |
31 | #[rustfmt::skip] | |
32 | on_slice(&vec!(1, 2)); | |
33 | on_slice(&[1, 2]); | |
34 | ||
35 | on_slice(&vec![1; 2]); | |
36 | on_slice(&[1; 2]); | |
37 | ||
38 | on_vec(&vec![]); | |
39 | on_vec(&vec![1, 2]); | |
40 | on_vec(&vec![1; 2]); | |
41 | ||
42 | // Now with non-constant expressions | |
43 | let line = Line { length: 2 }; | |
44 | ||
45 | on_slice(&vec![2; line.length]); | |
46 | on_slice(&vec![2; line.length()]); | |
47 | ||
48 | for a in vec![1, 2, 3] { | |
49 | println!("{:?}", a); | |
50 | } | |
51 | ||
52 | for a in vec![NonCopy, NonCopy] { | |
53 | println!("{:?}", a); | |
54 | } | |
55 | ||
56 | on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` | |
57 | ||
58 | // Ok | |
59 | for a in vec![1; 201] { | |
60 | println!("{:?}", a); | |
61 | } | |
62 | } |