]> git.lizzy.rs Git - rust.git/blob - tests/ui/non_expressive_names.rs
Merge branch 'master' into rustfmt_tests
[rust.git] / tests / ui / non_expressive_names.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 #![warn(clippy::all, clippy::similar_names)]
11 #![allow(unused, clippy::println_empty_string)]
12
13 struct Foo {
14     apple: i32,
15     bpple: i32,
16 }
17
18 fn main() {
19     let specter: i32;
20     let spectre: i32;
21
22     let apple: i32;
23
24     let bpple: i32;
25
26     let cpple: i32;
27
28     let a_bar: i32;
29     let b_bar: i32;
30     let c_bar: i32;
31
32     let items = [5];
33     for item in &items {
34         loop {}
35     }
36
37     let foo_x: i32;
38     let foo_y: i32;
39
40     let rhs: i32;
41     let lhs: i32;
42
43     let bla_rhs: i32;
44     let bla_lhs: i32;
45
46     let blubrhs: i32;
47     let blublhs: i32;
48
49     let blubx: i32;
50     let bluby: i32;
51
52     let cake: i32;
53     let cakes: i32;
54     let coke: i32;
55
56     match 5 {
57         cheese @ 1 => {},
58         rabbit => panic!(),
59     }
60     let cheese: i32;
61     match (42, 43) {
62         (cheese1, 1) => {},
63         (cheese2, 2) => panic!(),
64         _ => println!(""),
65     }
66     let ipv4: i32;
67     let ipv6: i32;
68     let abcd1: i32;
69     let abdc2: i32;
70     let xyz1abc: i32;
71     let xyz2abc: i32;
72     let xyzeabc: i32;
73
74     let parser: i32;
75     let parsed: i32;
76     let parsee: i32;
77
78     let setter: i32;
79     let getter: i32;
80     let tx1: i32;
81     let rx1: i32;
82     let tx_cake: i32;
83     let rx_cake: i32;
84 }
85
86 fn foo() {
87     let Foo { apple, bpple } = unimplemented!();
88     let Foo {
89         apple: spring,
90         bpple: sprang,
91     } = unimplemented!();
92 }
93
94 #[derive(Clone, Debug)]
95 enum MaybeInst {
96     Split,
97     Split1(usize),
98     Split2(usize),
99 }
100
101 struct InstSplit {
102     uiae: usize,
103 }
104
105 impl MaybeInst {
106     fn fill(&mut self) {
107         let filled = match *self {
108             MaybeInst::Split1(goto1) => panic!(1),
109             MaybeInst::Split2(goto2) => panic!(2),
110             _ => unimplemented!(),
111         };
112         unimplemented!()
113     }
114 }
115
116 fn bla() {
117     let a: i32;
118     let (b, c, d): (i32, i64, i16);
119     {
120         {
121             let cdefg: i32;
122             let blar: i32;
123         }
124         {
125             let e: i32;
126         }
127         {
128             let e: i32;
129             let f: i32;
130         }
131         match 5 {
132             1 => println!(""),
133             e => panic!(),
134         }
135         match 5 {
136             1 => println!(""),
137             _ => panic!(),
138         }
139     }
140 }
141
142 fn underscores_and_numbers() {
143     let _1 = 1; //~ERROR Consider a more descriptive name
144     let ____1 = 1; //~ERROR Consider a more descriptive name
145     let __1___2 = 12; //~ERROR Consider a more descriptive name
146     let _1_ok = 1;
147 }
148
149 fn issue2927() {
150     let args = 1;
151     format!("{:?}", 2);
152 }
153
154 fn issue3078() {
155     match "a" {
156         stringify!(a) => {},
157         _ => {},
158     }
159 }
160
161 struct Bar;
162
163 impl Bar {
164     fn bar() {
165         let _1 = 1;
166         let ____1 = 1;
167         let __1___2 = 12;
168         let _1_ok = 1;
169     }
170 }
171
172 // false positive similar_names (#3057, #2651)
173 // clippy claimed total_reg_src_size and total_size and
174 // numb_reg_src_checkouts and total_bin_size were similar
175 #[derive(Debug, Clone)]
176 pub(crate) struct DirSizes {
177     pub(crate) total_size: u64,
178     pub(crate) numb_bins: u64,
179     pub(crate) total_bin_size: u64,
180     pub(crate) total_reg_size: u64,
181     pub(crate) total_git_db_size: u64,
182     pub(crate) total_git_repos_bare_size: u64,
183     pub(crate) numb_git_repos_bare_repos: u64,
184     pub(crate) numb_git_checkouts: u64,
185     pub(crate) total_git_chk_size: u64,
186     pub(crate) total_reg_cache_size: u64,
187     pub(crate) total_reg_src_size: u64,
188     pub(crate) numb_reg_cache_entries: u64,
189     pub(crate) numb_reg_src_checkouts: u64,
190 }