1 #![allow(blacklisted_name, collapsible_if, cyclomatic_complexity, eq_op, needless_continue,
2 needless_return, never_loop, no_effect, zero_divided_by_zero)]
5 fn foo() -> bool { unimplemented!() }
17 #[warn(if_same_then_else)]
18 #[warn(match_same_arms)]
19 fn if_same_then_else() -> Result<&'static str, ()> {
29 else { //~ ERROR same body as `if` block
71 let mut a = 42 + [23].len() as i32;
78 _ => { //~ ERROR match arms have same body
80 let mut a = 42 + [23].len() as i32;
89 let _ = match Abc::A {
92 _ => 0, //~ ERROR match arms have same body
102 else { //~ ERROR same body as `if` block
108 let foo: &Option<_> = &Some::<u8>(42);
116 else { //~ ERROR same body as `if` block
118 let foo: &Option<_> = &Some::<u8>(42);
135 while foo() { break; }
138 else { //~ ERROR same body as `if` block
146 while foo() { break; }
171 if let Some(a) = Some(42) {}
173 else { //~ ERROR same body as `if` block
174 if let Some(a) = Some(42) {}
178 if let (1, .., 3) = (1, 2, 3) {}
180 else { //~ ERROR same body as `if` block
181 if let (1, .., 3) = (1, 2, 3) {}
185 if let (1, .., 3) = (1, 2, 3) {}
188 if let (.., 3) = (1, 2, 3) {}
192 if let (1, .., 3) = (1, 2, 3) {}
195 if let (.., 4) = (1, 2, 3) {}
199 if let (1, .., 3) = (1, 2, 3) {}
202 if let (.., 1, 3) = (1, 2, 3) {}
206 if let Some(42) = None {}
209 if let Option::Some(42) = None {}
213 if let Some(42) = None::<u8> {}
216 if let Some(42) = None {}
220 if let Some(42) = None::<u8> {}
223 if let Some(42) = None::<u32> {}
227 if let Some(a) = Some(42) {}
230 if let Some(a) = Some(43) {}
235 51 => foo(), //~ ERROR match arms have same body
239 let _ = match Some(42) {
241 None => 24, //~ ERROR match arms have same body
244 let _ = match Some(42) {
249 let _ = match Some(42) {
251 Some(a) => 24, // bindings are different
255 let _ = match Some(42) {
256 Some(a) if a > 0 => 24,
257 Some(a) => 24, // one arm has a guard
261 match (Some(42), Some(42)) {
262 (Some(a), None) => bar(a),
263 (None, Some(a)) => bar(a), //~ ERROR match arms have same body
267 match (Some(42), Some(42)) {
268 (Some(a), ..) => bar(a),
269 (.., Some(a)) => bar(a), //~ ERROR match arms have same body
275 (.., 3) => 42, //~ ERROR match arms have same body
281 } else { //~ ERROR same body as `if` block
287 } else { //~ ERROR same body as `if` block
307 } else { //~ ERROR same body as `if` block
311 let _ = match Some(()) {
316 match (Some(42), Some("")) {
317 (Some(a), None) => bar(a),
318 (None, Some(a)) => bar(a), // bindings have different types
325 else { //~ ERROR same body as `if` block
331 return Ok(&foo[0..]);
335 return Ok(&foo[0..]);
339 return Ok(&foo[0..]);
343 #[warn(ifs_same_cond)]
344 #[allow(if_same_then_else)] // all empty blocks
351 else if b { //~ ERROR ifs same condition
356 else if a == 1 { //~ ERROR ifs same condition
363 else if 2*a == 1 { //~ ERROR ifs same condition
369 if cfg!(feature = "feature1-659") {
371 } else if cfg!(feature = "feature2-659") {
378 if v.pop() == None { // ok, functions
380 else if v.pop() == None {
383 if v.len() == 42 { // ok, functions
385 else if v.len() == 42 {
391 // Issue #2423. This was causing an ICE