]> git.lizzy.rs Git - rust.git/blob - tests/ui/vec.rs
Merge pull request #3265 from mikerite/fix-export
[rust.git] / tests / ui / vec.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11 #![feature(tool_lints)]
12
13
14 #![warn(clippy::useless_vec)]
15
16 #[derive(Debug)]
17 struct NonCopy;
18
19 fn on_slice(_: &[u8]) {}
20 #[allow(clippy::ptr_arg)]
21 fn on_vec(_: &Vec<u8>) {}
22
23 struct Line {
24     length: usize,
25 }
26
27 impl Line {
28     fn length(&self) -> usize {
29         self.length
30     }
31 }
32
33 fn main() {
34     on_slice(&vec![]);
35     on_slice(&[]);
36
37     on_slice(&vec![1, 2]);
38     on_slice(&[1, 2]);
39
40     on_slice(&vec ![1, 2]);
41     on_slice(&[1, 2]);
42
43     on_slice(&vec!(1, 2));
44     on_slice(&[1, 2]);
45
46     on_slice(&vec![1; 2]);
47     on_slice(&[1; 2]);
48
49     on_vec(&vec![]);
50     on_vec(&vec![1, 2]);
51     on_vec(&vec![1; 2]);
52
53     // Now with non-constant expressions
54     let line = Line { length: 2 };
55
56     on_slice(&vec![2; line.length]);
57     on_slice(&vec![2; line.length()]);
58
59     for a in vec![1, 2, 3] {
60         println!("{:?}", a);
61     }
62
63     for a in vec![NonCopy, NonCopy] {
64         println!("{:?}", a);
65     }
66 }