1 #![warn(clippy::if_same_then_else)]
3 clippy::blacklisted_name,
4 clippy::collapsible_else_if,
5 clippy::collapsible_if,
7 clippy::needless_return,
8 clippy::single_element_loop,
9 clippy::branches_sharing_code
12 fn if_same_then_else2() -> Result<&'static str, ()> {
15 let foo: &Option<_> = &Some::<u8>(42);
23 //~ ERROR same body as `if` block
25 let bar: &Option<_> = &Some::<u8>(42);
35 if let Some(a) = Some(42) {}
37 //~ ERROR same body as `if` block
38 if let Some(a) = Some(42) {}
42 if let (1, .., 3) = (1, 2, 3) {}
44 //~ ERROR same body as `if` block
45 if let (1, .., 3) = (1, 2, 3) {}
49 if let (1, .., 3) = (1, 2, 3) {}
51 if let (.., 3) = (1, 2, 3) {}
55 if let (1, .., 3) = (1, 2, 3) {}
57 if let (.., 4) = (1, 2, 3) {}
61 if let (1, .., 3) = (1, 2, 3) {}
63 if let (.., 1, 3) = (1, 2, 3) {}
67 if let Some(42) = None {}
69 if let Option::Some(42) = None {}
73 if let Some(42) = None::<u8> {}
75 if let Some(42) = None {}
79 if let Some(42) = None::<u8> {}
81 if let Some(42) = None::<u32> {}
85 if let Some(a) = Some(42) {}
87 if let Some(a) = Some(43) {}
94 //~ ERROR same body as `if` block
101 //~ ERROR same body as `if` block
107 return Ok(&foo[0..]);
110 return Ok(&foo[0..]);
113 return Ok(&foo[0..]);
118 return Ok(&foo[0..]);
121 return Ok(&foo[0..]);
124 return Ok(&foo[0..]);
127 return Ok(&foo[0..]);
130 // False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559.
134 return Ok(&foo[x..y]);
138 return Ok(&foo[x..y]);