1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
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.
11 clippy::blacklisted_name,
12 clippy::collapsible_if,
13 clippy::cyclomatic_complexity,
15 clippy::needless_continue,
16 clippy::needless_return,
19 clippy::zero_divided_by_zero,
38 #[warn(clippy::if_same_then_else)]
39 #[warn(clippy::match_same_arms)]
40 #[allow(clippy::unused_unit)]
41 fn if_same_then_else() -> Result<&'static str, ()> {
51 //~ ERROR same body as `if` block
89 let mut a = 42 + [23].len() as i32;
97 //~ ERROR match arms have same body
99 let mut a = 42 + [23].len() as i32;
108 let _ = match Abc::A {
111 _ => 0, //~ ERROR match arms have same body
121 //~ ERROR same body as `if` block
127 let foo: &Option<_> = &Some::<u8>(42);
135 //~ ERROR same body as `if` block
137 let foo: &Option<_> = &Some::<u8>(42);
147 let bar = if true { 42 } else { 43 };
154 //~ ERROR same body as `if` block
155 let bar = if true { 42 } else { 43 };
182 if let Some(a) = Some(42) {}
184 //~ ERROR same body as `if` block
185 if let Some(a) = Some(42) {}
189 if let (1, .., 3) = (1, 2, 3) {}
191 //~ ERROR same body as `if` block
192 if let (1, .., 3) = (1, 2, 3) {}
196 if let (1, .., 3) = (1, 2, 3) {}
198 if let (.., 3) = (1, 2, 3) {}
202 if let (1, .., 3) = (1, 2, 3) {}
204 if let (.., 4) = (1, 2, 3) {}
208 if let (1, .., 3) = (1, 2, 3) {}
210 if let (.., 1, 3) = (1, 2, 3) {}
214 if let Some(42) = None {}
216 if let Option::Some(42) = None {}
220 if let Some(42) = None::<u8> {}
222 if let Some(42) = None {}
226 if let Some(42) = None::<u8> {}
228 if let Some(42) = None::<u32> {}
232 if let Some(a) = Some(42) {}
234 if let Some(a) = Some(43) {}
239 51 => foo(), //~ ERROR match arms have same body
243 let _ = match Some(42) {
245 None => 24, //~ ERROR match arms have same body
248 let _ = match Some(42) {
253 let _ = match Some(42) {
255 Some(a) => 24, // bindings are different
259 let _ = match Some(42) {
260 Some(a) if a > 0 => 24,
261 Some(a) => 24, // one arm has a guard
265 match (Some(42), Some(42)) {
266 (Some(a), None) => bar(a),
267 (None, Some(a)) => bar(a), //~ ERROR match arms have same body
271 match (Some(42), Some(42)) {
272 (Some(a), ..) => bar(a),
273 (.., Some(a)) => bar(a), //~ ERROR match arms have same body
279 (.., 3) => 42, //~ ERROR match arms have same body
286 //~ ERROR same body as `if` block
293 //~ ERROR same body as `if` block
297 let _ = if true { 0.0 } else { -0.0 };
300 let _ = if true { 0.0 / 0.0 } else { std::f32::NAN };
306 //~ ERROR same body as `if` block
310 let _ = match Some(()) {
315 match (Some(42), Some("")) {
316 (Some(a), None) => bar(a),
317 (None, Some(a)) => bar(a), // bindings have different types
324 //~ ERROR same body as `if` block
330 return Ok(&foo[0..]);
333 return Ok(&foo[0..]);
336 return Ok(&foo[0..]);
340 #[warn(clippy::ifs_same_cond)]
341 #[allow(clippy::if_same_then_else)] // all empty blocks
348 //~ ERROR ifs same condition
353 //~ ERROR ifs same condition
357 } else if 2 * a == 2 {
358 } else if 2 * a == 1 {
359 //~ ERROR ifs same condition
364 if cfg!(feature = "feature1-659") {
366 } else if cfg!(feature = "feature2-659") {
375 } else if v.pop() == None {
380 } else if v.len() == 42 {
386 // Issue #2423. This was causing an ICE