]> git.lizzy.rs Git - rust.git/blob - tests/ui/vec.fixed
Auto merge of #3626 - phansch:rustfix_works, r=oli-obk
[rust.git] / tests / ui / vec.fixed
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 // run-rustfix
11
12 #![warn(clippy::useless_vec)]
13
14 #[derive(Debug)]
15 struct NonCopy;
16
17 fn on_slice(_: &[u8]) {}
18 #[allow(clippy::ptr_arg)]
19 fn on_vec(_: &Vec<u8>) {}
20
21 struct Line {
22     length: usize,
23 }
24
25 impl Line {
26     fn length(&self) -> usize {
27         self.length
28     }
29 }
30
31 fn main() {
32     on_slice(&[]);
33     on_slice(&[]);
34
35     on_slice(&[1, 2]);
36     on_slice(&[1, 2]);
37
38     on_slice(&[1, 2]);
39     on_slice(&[1, 2]);
40     #[rustfmt::skip]
41     on_slice(&[1, 2]);
42     on_slice(&[1, 2]);
43
44     on_slice(&[1; 2]);
45     on_slice(&[1; 2]);
46
47     on_vec(&vec![]);
48     on_vec(&vec![1, 2]);
49     on_vec(&vec![1; 2]);
50
51     // Now with non-constant expressions
52     let line = Line { length: 2 };
53
54     on_slice(&vec![2; line.length]);
55     on_slice(&vec![2; line.length()]);
56
57     for a in &[1, 2, 3] {
58         println!("{:?}", a);
59     }
60
61     for a in vec![NonCopy, NonCopy] {
62         println!("{:?}", a);
63     }
64 }