1 #![feature(tool_lints)]
3 #![allow(clippy::blacklisted_name, clippy::collapsible_if, clippy::cyclomatic_complexity, clippy::eq_op, clippy::needless_continue,
4 clippy::needless_return, clippy::never_loop, clippy::no_effect, clippy::zero_divided_by_zero)]
7 fn foo() -> bool { unimplemented!() }
19 #[warn(clippy::if_same_then_else)]
20 #[warn(clippy::match_same_arms)]
21 fn if_same_then_else() -> Result<&'static str, ()> {
31 else { //~ ERROR same body as `if` block
73 let mut a = 42 + [23].len() as i32;
80 _ => { //~ ERROR match arms have same body
82 let mut a = 42 + [23].len() as i32;
91 let _ = match Abc::A {
94 _ => 0, //~ ERROR match arms have same body
104 else { //~ ERROR same body as `if` block
110 let foo: &Option<_> = &Some::<u8>(42);
118 else { //~ ERROR same body as `if` block
120 let foo: &Option<_> = &Some::<u8>(42);
137 while foo() { break; }
140 else { //~ ERROR same body as `if` block
148 while foo() { break; }
173 if let Some(a) = Some(42) {}
175 else { //~ ERROR same body as `if` block
176 if let Some(a) = Some(42) {}
180 if let (1, .., 3) = (1, 2, 3) {}
182 else { //~ ERROR same body as `if` block
183 if let (1, .., 3) = (1, 2, 3) {}
187 if let (1, .., 3) = (1, 2, 3) {}
190 if let (.., 3) = (1, 2, 3) {}
194 if let (1, .., 3) = (1, 2, 3) {}
197 if let (.., 4) = (1, 2, 3) {}
201 if let (1, .., 3) = (1, 2, 3) {}
204 if let (.., 1, 3) = (1, 2, 3) {}
208 if let Some(42) = None {}
211 if let Option::Some(42) = None {}
215 if let Some(42) = None::<u8> {}
218 if let Some(42) = None {}
222 if let Some(42) = None::<u8> {}
225 if let Some(42) = None::<u32> {}
229 if let Some(a) = Some(42) {}
232 if let Some(a) = Some(43) {}
237 51 => foo(), //~ ERROR match arms have same body
241 let _ = match Some(42) {
243 None => 24, //~ ERROR match arms have same body
246 let _ = match Some(42) {
251 let _ = match Some(42) {
253 Some(a) => 24, // bindings are different
257 let _ = match Some(42) {
258 Some(a) if a > 0 => 24,
259 Some(a) => 24, // one arm has a guard
263 match (Some(42), Some(42)) {
264 (Some(a), None) => bar(a),
265 (None, Some(a)) => bar(a), //~ ERROR match arms have same body
269 match (Some(42), Some(42)) {
270 (Some(a), ..) => bar(a),
271 (.., Some(a)) => bar(a), //~ ERROR match arms have same body
277 (.., 3) => 42, //~ ERROR match arms have same body
283 } else { //~ ERROR same body as `if` block
289 } else { //~ ERROR same body as `if` block
309 } else { //~ ERROR same body as `if` block
313 let _ = match Some(()) {
318 match (Some(42), Some("")) {
319 (Some(a), None) => bar(a),
320 (None, Some(a)) => bar(a), // bindings have different types
327 else { //~ ERROR same body as `if` block
333 return Ok(&foo[0..]);
337 return Ok(&foo[0..]);
341 return Ok(&foo[0..]);
345 #[warn(clippy::ifs_same_cond)]
346 #[allow(clippy::if_same_then_else)] // all empty blocks
353 else if b { //~ ERROR ifs same condition
358 else if a == 1 { //~ ERROR ifs same condition
365 else if 2*a == 1 { //~ ERROR ifs same condition
371 if cfg!(feature = "feature1-659") {
373 } else if cfg!(feature = "feature2-659") {
380 if v.pop() == None { // ok, functions
382 else if v.pop() == None {
385 if v.len() == 42 { // ok, functions
387 else if v.len() == 42 {
393 // Issue #2423. This was causing an ICE