]> git.lizzy.rs Git - rust.git/blob - tests/ui/vec.rs
rustup and compile-fail -> ui test move
[rust.git] / tests / ui / vec.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![deny(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     //~^ ERROR useless use of `vec!`
26     //~| HELP you can use
27     //~| SUGGESTION on_slice(&[])
28     on_slice(&[]);
29
30     on_slice(&vec![1, 2]);
31     //~^ ERROR useless use of `vec!`
32     //~| HELP you can use
33     //~| SUGGESTION on_slice(&[1, 2])
34     on_slice(&[1, 2]);
35
36     on_slice(&vec ![1, 2]);
37     //~^ ERROR useless use of `vec!`
38     //~| HELP you can use
39     //~| SUGGESTION on_slice(&[1, 2])
40     on_slice(&[1, 2]);
41
42     on_slice(&vec!(1, 2));
43     //~^ ERROR useless use of `vec!`
44     //~| HELP you can use
45     //~| SUGGESTION on_slice(&[1, 2])
46     on_slice(&[1, 2]);
47
48     on_slice(&vec![1; 2]);
49     //~^ ERROR useless use of `vec!`
50     //~| HELP you can use
51     //~| SUGGESTION on_slice(&[1; 2])
52     on_slice(&[1; 2]);
53
54     on_vec(&vec![]);
55     on_vec(&vec![1, 2]);
56     on_vec(&vec![1; 2]);
57
58     // Now with non-constant expressions
59     let line = Line { length: 2 };
60
61     on_slice(&vec![2; line.length]);
62     on_slice(&vec![2; line.length()]);
63
64     for a in vec![1, 2, 3] {
65         //~^ ERROR useless use of `vec!`
66         //~| HELP you can use
67         //~| SUGGESTION for a in &[1, 2, 3] {
68         println!("{:?}", a);
69     }
70
71     for a in vec![NonCopy, NonCopy] {
72         println!("{:?}", a);
73     }
74 }