1 #![warn(clippy::if_same_then_else)]
3 clippy::disallowed_names,
4 clippy::collapsible_else_if,
5 clippy::equatable_if_let,
6 clippy::collapsible_if,
8 clippy::needless_return,
9 clippy::single_element_loop,
10 clippy::branches_sharing_code
13 fn if_same_then_else2() -> Result<&'static str, ()> {
16 let foo: &Option<_> = &Some::<u8>(42);
24 //~ ERROR same body as `if` block
26 let bar: &Option<_> = &Some::<u8>(42);
36 if let Some(a) = Some(42) {}
38 //~ ERROR same body as `if` block
39 if let Some(a) = Some(42) {}
43 if let (1, .., 3) = (1, 2, 3) {}
45 //~ ERROR same body as `if` block
46 if let (1, .., 3) = (1, 2, 3) {}
50 if let (1, .., 3) = (1, 2, 3) {}
52 if let (.., 3) = (1, 2, 3) {}
56 if let (1, .., 3) = (1, 2, 3) {}
58 if let (.., 4) = (1, 2, 3) {}
62 if let (1, .., 3) = (1, 2, 3) {}
64 if let (.., 1, 3) = (1, 2, 3) {}
68 if let Some(42) = None {}
70 if let Option::Some(42) = None {}
74 if let Some(42) = None::<u8> {}
76 if let Some(42) = None {}
80 if let Some(42) = None::<u8> {}
82 if let Some(42) = None::<u32> {}
86 if let Some(a) = Some(42) {}
88 if let Some(a) = Some(43) {}
95 //~ ERROR same body as `if` block
102 //~ ERROR same body as `if` block
108 return Ok(&foo[0..]);
111 return Ok(&foo[0..]);
114 return Ok(&foo[0..]);
119 return Ok(&foo[0..]);
122 return Ok(&foo[0..]);
125 return Ok(&foo[0..]);
128 return Ok(&foo[0..]);
131 // False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559.
135 return Ok(&foo[x..y]);
139 return Ok(&foo[x..y]);
143 let _ = if let Some(0) = None { 0 } else { 0 };
147 } else if let Some(0) = None {
151 let _ = if let Some(0) = None {
153 } else if let Some(1) = None {