]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/vec.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / vec.rs
1
2
3
4 #![warn(useless_vec)]
5
6 #[derive(Debug)]
7 struct NonCopy;
8
9 fn on_slice(_: &[u8]) {}
10 #[allow(ptr_arg)]
11 fn on_vec(_: &Vec<u8>) {}
12
13 struct Line {
14 length: usize,
15 }
16
17 impl Line {
18 fn length(&self) -> usize {
19 self.length
20 }
21 }
22
23 fn main() {
24 on_slice(&vec![]);
25 on_slice(&[]);
26
27 on_slice(&vec![1, 2]);
28 on_slice(&[1, 2]);
29
30 on_slice(&vec ![1, 2]);
31 on_slice(&[1, 2]);
32
33 on_slice(&vec!(1, 2));
34 on_slice(&[1, 2]);
35
36 on_slice(&vec![1; 2]);
37 on_slice(&[1; 2]);
38
39 on_vec(&vec![]);
40 on_vec(&vec![1, 2]);
41 on_vec(&vec![1; 2]);
42
43 // Now with non-constant expressions
44 let line = Line { length: 2 };
45
46 on_slice(&vec![2; line.length]);
47 on_slice(&vec![2; line.length()]);
48
49 for a in vec![1, 2, 3] {
50 println!("{:?}", a);
51 }
52
53 for a in vec![NonCopy, NonCopy] {
54 println!("{:?}", a);
55 }
56 }