Auto merge of #3755 - phansch:uicleanup2, r=oli-obk
UI test cleanup: Extract match_same_arms tests cc #2038
This commit is contained in:
commit
83edb647f2
@ -1,355 +0,0 @@
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:41:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | Foo { bar: 42 };
|
||||
LL | | 0..10;
|
||||
... |
|
||||
LL | | foo();
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::if-same-then-else` implied by `-D warnings`
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:33:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | Foo { bar: 42 };
|
||||
LL | | 0..10;
|
||||
LL | | ..;
|
||||
... |
|
||||
LL | | foo();
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:87:14
|
||||
|
|
||||
LL | _ => {
|
||||
| ______________^
|
||||
LL | | //~ ERROR match arms have same body
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
= note: `-D clippy::match-same-arms` implied by `-D warnings`
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:78:15
|
||||
|
|
||||
LL | 42 => {
|
||||
| _______________^
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
note: `42` has the same arm body as the `_` wildcard, consider removing it`
|
||||
--> $DIR/copies.rs:78:15
|
||||
|
|
||||
LL | 42 => {
|
||||
| _______________^
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:102:14
|
||||
|
|
||||
LL | _ => 0, //~ ERROR match arms have same body
|
||||
| ^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:100:19
|
||||
|
|
||||
LL | Abc::A => 0,
|
||||
| ^
|
||||
note: `Abc::A` has the same arm body as the `_` wildcard, consider removing it`
|
||||
--> $DIR/copies.rs:100:19
|
||||
|
|
||||
LL | Abc::A => 0,
|
||||
| ^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:111:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | 42
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:109:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | 42
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:125:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | for _ in &[42] {
|
||||
LL | | let foo: &Option<_> = &Some::<u8>(42);
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:116:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | for _ in &[42] {
|
||||
LL | | let foo: &Option<_> = &Some::<u8>(42);
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | }
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:144:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | let bar = if true { 42 } else { 43 };
|
||||
LL | |
|
||||
... |
|
||||
LL | | bar + 1;
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:137:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | let bar = if true { 42 } else { 43 };
|
||||
LL | |
|
||||
LL | | while foo() {
|
||||
... |
|
||||
LL | | bar + 1;
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:174:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | if let Some(a) = Some(42) {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:172:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | if let Some(a) = Some(42) {}
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:181:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | if let (1, .., 3) = (1, 2, 3) {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:179:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | if let (1, .., 3) = (1, 2, 3) {}
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:230:15
|
||||
|
|
||||
LL | 51 => foo(), //~ ERROR match arms have same body
|
||||
| ^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:229:15
|
||||
|
|
||||
LL | 42 => foo(),
|
||||
| ^^^^^
|
||||
note: consider refactoring into `42 | 51`
|
||||
--> $DIR/copies.rs:229:15
|
||||
|
|
||||
LL | 42 => foo(),
|
||||
| ^^^^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:236:17
|
||||
|
|
||||
LL | None => 24, //~ ERROR match arms have same body
|
||||
| ^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:235:20
|
||||
|
|
||||
LL | Some(_) => 24,
|
||||
| ^^
|
||||
note: consider refactoring into `Some(_) | None`
|
||||
--> $DIR/copies.rs:235:20
|
||||
|
|
||||
LL | Some(_) => 24,
|
||||
| ^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:258:28
|
||||
|
|
||||
LL | (None, Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
| ^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:257:28
|
||||
|
|
||||
LL | (Some(a), None) => bar(a),
|
||||
| ^^^^^^
|
||||
note: consider refactoring into `(Some(a), None) | (None, Some(a))`
|
||||
--> $DIR/copies.rs:257:28
|
||||
|
|
||||
LL | (Some(a), None) => bar(a),
|
||||
| ^^^^^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:264:26
|
||||
|
|
||||
LL | (.., Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
| ^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:263:26
|
||||
|
|
||||
LL | (Some(a), ..) => bar(a),
|
||||
| ^^^^^^
|
||||
note: consider refactoring into `(Some(a), ..) | (.., Some(a))`
|
||||
--> $DIR/copies.rs:263:26
|
||||
|
|
||||
LL | (Some(a), ..) => bar(a),
|
||||
| ^^^^^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/copies.rs:270:20
|
||||
|
|
||||
LL | (.., 3) => 42, //~ ERROR match arms have same body
|
||||
| ^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:269:23
|
||||
|
|
||||
LL | (1, .., 3) => 42,
|
||||
| ^^
|
||||
note: consider refactoring into `(1, .., 3) | (.., 3)`
|
||||
--> $DIR/copies.rs:269:23
|
||||
|
|
||||
LL | (1, .., 3) => 42,
|
||||
| ^^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:276:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | 0.0
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:274:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | 0.0
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:283:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | -0.0
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:281:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | -0.0
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:296:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | std::f32::NAN
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:294:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | std::f32::NAN
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/copies.rs:314:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | try!(Ok("foo"));
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/copies.rs:312:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | try!(Ok("foo"));
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
@ -1,9 +1,9 @@
|
||||
#![warn(clippy::if_same_then_else)]
|
||||
#![allow(
|
||||
clippy::blacklisted_name,
|
||||
clippy::collapsible_if,
|
||||
clippy::cyclomatic_complexity,
|
||||
clippy::eq_op,
|
||||
clippy::needless_continue,
|
||||
clippy::needless_return,
|
||||
clippy::never_loop,
|
||||
clippy::no_effect,
|
||||
@ -11,24 +11,14 @@
|
||||
clippy::unused_unit
|
||||
)]
|
||||
|
||||
fn bar<T>(_: T) {}
|
||||
fn foo() -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
bar: u8,
|
||||
}
|
||||
|
||||
pub enum Abc {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
fn foo() -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[warn(clippy::if_same_then_else)]
|
||||
#[warn(clippy::match_same_arms)]
|
||||
#[allow(clippy::unused_unit)]
|
||||
fn if_same_then_else() -> Result<&'static str, ()> {
|
||||
if true {
|
||||
Foo { bar: 42 };
|
||||
@ -74,34 +64,25 @@ fn if_same_then_else() -> Result<&'static str, ()> {
|
||||
foo();
|
||||
}
|
||||
|
||||
let _ = match 42 {
|
||||
42 => {
|
||||
foo();
|
||||
let mut a = 42 + [23].len() as i32;
|
||||
if true {
|
||||
a += 7;
|
||||
}
|
||||
a = -31 - a;
|
||||
a
|
||||
},
|
||||
_ => {
|
||||
//~ ERROR match arms have same body
|
||||
foo();
|
||||
let mut a = 42 + [23].len() as i32;
|
||||
if true {
|
||||
a += 7;
|
||||
}
|
||||
a = -31 - a;
|
||||
a
|
||||
},
|
||||
let _ = if true {
|
||||
0.0
|
||||
} else {
|
||||
//~ ERROR same body as `if` block
|
||||
0.0
|
||||
};
|
||||
|
||||
let _ = match Abc::A {
|
||||
Abc::A => 0,
|
||||
Abc::B => 1,
|
||||
_ => 0, //~ ERROR match arms have same body
|
||||
let _ = if true {
|
||||
-0.0
|
||||
} else {
|
||||
//~ ERROR same body as `if` block
|
||||
-0.0
|
||||
};
|
||||
|
||||
let _ = if true { 0.0 } else { -0.0 };
|
||||
|
||||
// Different NaNs
|
||||
let _ = if true { 0.0 / 0.0 } else { std::f32::NAN };
|
||||
|
||||
if true {
|
||||
foo();
|
||||
}
|
||||
@ -225,71 +206,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
|
||||
if let Some(a) = Some(43) {}
|
||||
}
|
||||
|
||||
let _ = match 42 {
|
||||
42 => foo(),
|
||||
51 => foo(), //~ ERROR match arms have same body
|
||||
_ => true,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(_) => 24,
|
||||
None => 24, //~ ERROR match arms have same body
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(foo) => 24,
|
||||
None => 24,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(42) => 24,
|
||||
Some(a) => 24, // bindings are different
|
||||
None => 0,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(a) if a > 0 => 24,
|
||||
Some(a) => 24, // one arm has a guard
|
||||
None => 0,
|
||||
};
|
||||
|
||||
match (Some(42), Some(42)) {
|
||||
(Some(a), None) => bar(a),
|
||||
(None, Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
_ => (),
|
||||
}
|
||||
|
||||
match (Some(42), Some(42)) {
|
||||
(Some(a), ..) => bar(a),
|
||||
(.., Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
_ => (),
|
||||
}
|
||||
|
||||
match (1, 2, 3) {
|
||||
(1, .., 3) => 42,
|
||||
(.., 3) => 42, //~ ERROR match arms have same body
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
let _ = if true {
|
||||
0.0
|
||||
} else {
|
||||
//~ ERROR same body as `if` block
|
||||
0.0
|
||||
};
|
||||
|
||||
let _ = if true {
|
||||
-0.0
|
||||
} else {
|
||||
//~ ERROR same body as `if` block
|
||||
-0.0
|
||||
};
|
||||
|
||||
let _ = if true { 0.0 } else { -0.0 };
|
||||
|
||||
// Different NaNs
|
||||
let _ = if true { 0.0 / 0.0 } else { std::f32::NAN };
|
||||
|
||||
// Same NaNs
|
||||
let _ = if true {
|
||||
std::f32::NAN
|
||||
@ -298,17 +214,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
|
||||
std::f32::NAN
|
||||
};
|
||||
|
||||
let _ = match Some(()) {
|
||||
Some(()) => 0.0,
|
||||
None => -0.0,
|
||||
};
|
||||
|
||||
match (Some(42), Some("")) {
|
||||
(Some(a), None) => bar(a),
|
||||
(None, Some(a)) => bar(a), // bindings have different types
|
||||
_ => (),
|
||||
}
|
||||
|
||||
if true {
|
||||
try!(Ok("foo"));
|
||||
} else {
|
||||
@ -339,8 +244,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
// Issue #2423. This was causing an ICE
|
||||
fn func() {
|
||||
if true {
|
||||
@ -355,3 +258,5 @@ fn func() {
|
||||
}
|
||||
|
||||
fn f(val: &[u8]) {}
|
||||
|
||||
fn main() {}
|
214
tests/ui/if_same_then_else.stderr
Normal file
214
tests/ui/if_same_then_else.stderr
Normal file
@ -0,0 +1,214 @@
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:31:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | Foo { bar: 42 };
|
||||
LL | | 0..10;
|
||||
... |
|
||||
LL | | foo();
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
= note: `-D clippy::if-same-then-else` implied by `-D warnings`
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:23:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | Foo { bar: 42 };
|
||||
LL | | 0..10;
|
||||
LL | | ..;
|
||||
... |
|
||||
LL | | foo();
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:69:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | 0.0
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:67:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | 0.0
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:76:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | -0.0
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:74:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | -0.0
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:92:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | 42
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:90:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | 42
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:106:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | for _ in &[42] {
|
||||
LL | | let foo: &Option<_> = &Some::<u8>(42);
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:97:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | for _ in &[42] {
|
||||
LL | | let foo: &Option<_> = &Some::<u8>(42);
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | }
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:125:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | let bar = if true { 42 } else { 43 };
|
||||
LL | |
|
||||
... |
|
||||
LL | | bar + 1;
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:118:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | let bar = if true { 42 } else { 43 };
|
||||
LL | |
|
||||
LL | | while foo() {
|
||||
... |
|
||||
LL | | bar + 1;
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:155:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | if let Some(a) = Some(42) {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:153:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | if let Some(a) = Some(42) {}
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:162:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | if let (1, .., 3) = (1, 2, 3) {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:160:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | if let (1, .., 3) = (1, 2, 3) {}
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:212:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | std::f32::NAN
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:210:21
|
||||
|
|
||||
LL | let _ = if true {
|
||||
| _____________________^
|
||||
LL | | std::f32::NAN
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else.rs:219:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | //~ ERROR same body as `if` block
|
||||
LL | | try!(Ok("foo"));
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else.rs:217:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | | try!(Ok("foo"));
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
113
tests/ui/match_same_arms.rs
Normal file
113
tests/ui/match_same_arms.rs
Normal file
@ -0,0 +1,113 @@
|
||||
#![allow(
|
||||
clippy::blacklisted_name,
|
||||
clippy::collapsible_if,
|
||||
clippy::cyclomatic_complexity,
|
||||
clippy::eq_op,
|
||||
clippy::needless_continue,
|
||||
clippy::needless_return,
|
||||
clippy::no_effect,
|
||||
clippy::zero_divided_by_zero,
|
||||
clippy::unused_unit
|
||||
)]
|
||||
|
||||
fn bar<T>(_: T) {}
|
||||
fn foo() -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub enum Abc {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
#[warn(clippy::match_same_arms)]
|
||||
#[allow(clippy::unused_unit)]
|
||||
fn match_same_arms() {
|
||||
let _ = match 42 {
|
||||
42 => {
|
||||
foo();
|
||||
let mut a = 42 + [23].len() as i32;
|
||||
if true {
|
||||
a += 7;
|
||||
}
|
||||
a = -31 - a;
|
||||
a
|
||||
},
|
||||
_ => {
|
||||
//~ ERROR match arms have same body
|
||||
foo();
|
||||
let mut a = 42 + [23].len() as i32;
|
||||
if true {
|
||||
a += 7;
|
||||
}
|
||||
a = -31 - a;
|
||||
a
|
||||
},
|
||||
};
|
||||
|
||||
let _ = match Abc::A {
|
||||
Abc::A => 0,
|
||||
Abc::B => 1,
|
||||
_ => 0, //~ ERROR match arms have same body
|
||||
};
|
||||
|
||||
let _ = match 42 {
|
||||
42 => foo(),
|
||||
51 => foo(), //~ ERROR match arms have same body
|
||||
_ => true,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(_) => 24,
|
||||
None => 24, //~ ERROR match arms have same body
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(foo) => 24,
|
||||
None => 24,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(42) => 24,
|
||||
Some(a) => 24, // bindings are different
|
||||
None => 0,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(a) if a > 0 => 24,
|
||||
Some(a) => 24, // one arm has a guard
|
||||
None => 0,
|
||||
};
|
||||
|
||||
match (Some(42), Some(42)) {
|
||||
(Some(a), None) => bar(a),
|
||||
(None, Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
_ => (),
|
||||
}
|
||||
|
||||
match (Some(42), Some(42)) {
|
||||
(Some(a), ..) => bar(a),
|
||||
(.., Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
_ => (),
|
||||
}
|
||||
|
||||
match (1, 2, 3) {
|
||||
(1, .., 3) => 42,
|
||||
(.., 3) => 42, //~ ERROR match arms have same body
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
let _ = match Some(()) {
|
||||
Some(()) => 0.0,
|
||||
None => -0.0,
|
||||
};
|
||||
|
||||
match (Some(42), Some("")) {
|
||||
(Some(a), None) => bar(a),
|
||||
(None, Some(a)) => bar(a), // bindings have different types
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
143
tests/ui/match_same_arms.stderr
Normal file
143
tests/ui/match_same_arms.stderr
Normal file
@ -0,0 +1,143 @@
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:37:14
|
||||
|
|
||||
LL | _ => {
|
||||
| ______________^
|
||||
LL | | //~ ERROR match arms have same body
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
= note: `-D clippy::match-same-arms` implied by `-D warnings`
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:28:15
|
||||
|
|
||||
LL | 42 => {
|
||||
| _______________^
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
note: `42` has the same arm body as the `_` wildcard, consider removing it`
|
||||
--> $DIR/match_same_arms.rs:28:15
|
||||
|
|
||||
LL | 42 => {
|
||||
| _______________^
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:52:14
|
||||
|
|
||||
LL | _ => 0, //~ ERROR match arms have same body
|
||||
| ^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:50:19
|
||||
|
|
||||
LL | Abc::A => 0,
|
||||
| ^
|
||||
note: `Abc::A` has the same arm body as the `_` wildcard, consider removing it`
|
||||
--> $DIR/match_same_arms.rs:50:19
|
||||
|
|
||||
LL | Abc::A => 0,
|
||||
| ^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:57:15
|
||||
|
|
||||
LL | 51 => foo(), //~ ERROR match arms have same body
|
||||
| ^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:56:15
|
||||
|
|
||||
LL | 42 => foo(),
|
||||
| ^^^^^
|
||||
note: consider refactoring into `42 | 51`
|
||||
--> $DIR/match_same_arms.rs:56:15
|
||||
|
|
||||
LL | 42 => foo(),
|
||||
| ^^^^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:63:17
|
||||
|
|
||||
LL | None => 24, //~ ERROR match arms have same body
|
||||
| ^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:62:20
|
||||
|
|
||||
LL | Some(_) => 24,
|
||||
| ^^
|
||||
note: consider refactoring into `Some(_) | None`
|
||||
--> $DIR/match_same_arms.rs:62:20
|
||||
|
|
||||
LL | Some(_) => 24,
|
||||
| ^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:85:28
|
||||
|
|
||||
LL | (None, Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
| ^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:84:28
|
||||
|
|
||||
LL | (Some(a), None) => bar(a),
|
||||
| ^^^^^^
|
||||
note: consider refactoring into `(Some(a), None) | (None, Some(a))`
|
||||
--> $DIR/match_same_arms.rs:84:28
|
||||
|
|
||||
LL | (Some(a), None) => bar(a),
|
||||
| ^^^^^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:91:26
|
||||
|
|
||||
LL | (.., Some(a)) => bar(a), //~ ERROR match arms have same body
|
||||
| ^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:90:26
|
||||
|
|
||||
LL | (Some(a), ..) => bar(a),
|
||||
| ^^^^^^
|
||||
note: consider refactoring into `(Some(a), ..) | (.., Some(a))`
|
||||
--> $DIR/match_same_arms.rs:90:26
|
||||
|
|
||||
LL | (Some(a), ..) => bar(a),
|
||||
| ^^^^^^
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms.rs:97:20
|
||||
|
|
||||
LL | (.., 3) => 42, //~ ERROR match arms have same body
|
||||
| ^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms.rs:96:23
|
||||
|
|
||||
LL | (1, .., 3) => 42,
|
||||
| ^^
|
||||
note: consider refactoring into `(1, .., 3) | (.., 3)`
|
||||
--> $DIR/match_same_arms.rs:96:23
|
||||
|
|
||||
LL | (1, .., 3) => 42,
|
||||
| ^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user