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