match_same_arms, ifs_same_cond: lint once per same arm/condition
This commit is contained in:
parent
8eed35023f
commit
39ab00a3a1
18 changed files with 747 additions and 399 deletions
|
|
@ -11,9 +11,9 @@ fn issue10272() {
|
|||
// should trigger warning
|
||||
let x = Cell::new(true);
|
||||
if x.get() {
|
||||
//~^ ifs_same_cond
|
||||
} else if !x.take() {
|
||||
} else if x.get() {
|
||||
//~^ ifs_same_cond
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
error: this `if` has the same condition as a previous `if`
|
||||
--> tests/ui-toml/ifs_same_cond/ifs_same_cond.rs:15:15
|
||||
|
|
||||
LL | } else if x.get() {
|
||||
| ^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same condition
|
||||
--> tests/ui-toml/ifs_same_cond/ifs_same_cond.rs:13:8
|
||||
|
|
||||
LL | if x.get() {
|
||||
| ^^^^^^^
|
||||
...
|
||||
LL | } else if x.get() {
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]`
|
||||
|
||||
|
|
|
|||
|
|
@ -6,19 +6,25 @@ fn ifs_same_cond() {
|
|||
let b = false;
|
||||
|
||||
if b {
|
||||
} else if b {
|
||||
//~^ ifs_same_cond
|
||||
} else if b {
|
||||
}
|
||||
|
||||
if b {
|
||||
//~^ ifs_same_cond
|
||||
} else if b {
|
||||
} else if b {
|
||||
}
|
||||
|
||||
if a == 1 {
|
||||
} else if a == 1 {
|
||||
//~^ ifs_same_cond
|
||||
} else if a == 1 {
|
||||
}
|
||||
|
||||
if 2 * a == 1 {
|
||||
//~^ ifs_same_cond
|
||||
} else if 2 * a == 2 {
|
||||
} else if 2 * a == 1 {
|
||||
//~^ ifs_same_cond
|
||||
} else if a == 1 {
|
||||
}
|
||||
|
||||
|
|
@ -50,8 +56,8 @@ fn ifs_same_cond() {
|
|||
fn issue10272() {
|
||||
let a = String::from("ha");
|
||||
if a.contains("ah") {
|
||||
} else if a.contains("ah") {
|
||||
//~^ ifs_same_cond
|
||||
} else if a.contains("ah") {
|
||||
|
||||
// Trigger this lint
|
||||
} else if a.contains("ha") {
|
||||
|
|
|
|||
|
|
@ -1,52 +1,52 @@
|
|||
error: this `if` has the same condition as a previous `if`
|
||||
--> tests/ui/ifs_same_cond.rs:9:15
|
||||
|
|
||||
LL | } else if b {
|
||||
| ^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same condition
|
||||
--> tests/ui/ifs_same_cond.rs:8:8
|
||||
|
|
||||
LL | if b {
|
||||
| ^
|
||||
LL |
|
||||
LL | } else if b {
|
||||
| ^
|
||||
|
|
||||
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::ifs_same_cond)]`
|
||||
|
||||
error: this `if` has the same condition as a previous `if`
|
||||
--> tests/ui/ifs_same_cond.rs:14:15
|
||||
|
|
||||
LL | } else if a == 1 {
|
||||
| ^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same condition
|
||||
--> tests/ui/ifs_same_cond.rs:13:8
|
||||
|
|
||||
LL | if b {
|
||||
| ^
|
||||
LL |
|
||||
LL | } else if b {
|
||||
| ^
|
||||
LL | } else if b {
|
||||
| ^
|
||||
|
||||
error: these `if` branches have the same condition
|
||||
--> tests/ui/ifs_same_cond.rs:19:8
|
||||
|
|
||||
LL | if a == 1 {
|
||||
| ^^^^^^
|
||||
LL |
|
||||
LL | } else if a == 1 {
|
||||
| ^^^^^^
|
||||
|
||||
error: this `if` has the same condition as a previous `if`
|
||||
--> tests/ui/ifs_same_cond.rs:20:15
|
||||
|
|
||||
LL | } else if 2 * a == 1 {
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> tests/ui/ifs_same_cond.rs:18:8
|
||||
error: these `if` branches have the same condition
|
||||
--> tests/ui/ifs_same_cond.rs:24:8
|
||||
|
|
||||
LL | if 2 * a == 1 {
|
||||
| ^^^^^^^^^^
|
||||
...
|
||||
LL | } else if 2 * a == 1 {
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: this `if` has the same condition as a previous `if`
|
||||
--> tests/ui/ifs_same_cond.rs:53:15
|
||||
|
|
||||
LL | } else if a.contains("ah") {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> tests/ui/ifs_same_cond.rs:52:8
|
||||
error: these `if` branches have the same condition
|
||||
--> tests/ui/ifs_same_cond.rs:58:8
|
||||
|
|
||||
LL | if a.contains("ah") {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | } else if a.contains("ah") {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
142
tests/ui/match_same_arms.fixed
Normal file
142
tests/ui/match_same_arms.fixed
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
#![allow(clippy::manual_range_patterns)]
|
||||
#![warn(clippy::match_same_arms)]
|
||||
|
||||
pub enum Abc {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
fn match_same_arms() {
|
||||
let _ = match Abc::A {
|
||||
Abc::B => 1,
|
||||
_ => 0,
|
||||
//~^ match_same_arms
|
||||
};
|
||||
|
||||
match 0 {
|
||||
1 => 'a',
|
||||
_ => 'b',
|
||||
//~^ match_same_arms
|
||||
};
|
||||
|
||||
match (1, 2, 3) {
|
||||
(1, .., 3) | (.., 3) => 42,
|
||||
//~^ match_same_arms
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
let _ = match 42 {
|
||||
//~^ match_same_arms
|
||||
42 | 51 => 1,
|
||||
41 | 52 => 2,
|
||||
//~^ match_same_arms
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
let _ = match 42 {
|
||||
//~^ match_same_arms
|
||||
1 | 2 | 3 => 2,
|
||||
4 => 3,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
||||
mod issue4244 {
|
||||
#[derive(PartialEq, PartialOrd, Eq, Ord)]
|
||||
pub enum CommandInfo {
|
||||
BuiltIn { name: String, about: Option<String> },
|
||||
External { name: String, path: std::path::PathBuf },
|
||||
}
|
||||
|
||||
impl CommandInfo {
|
||||
pub fn name(&self) -> String {
|
||||
match self {
|
||||
//~^ match_same_arms
|
||||
CommandInfo::BuiltIn { name, .. } | CommandInfo::External { name, .. } => name.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! m {
|
||||
(foo) => {};
|
||||
(bar) => {};
|
||||
}
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
1
|
||||
};
|
||||
}
|
||||
macro_rules! bar {
|
||||
() => {
|
||||
1
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 0;
|
||||
let _ = match 0 {
|
||||
0 => {
|
||||
m!(foo);
|
||||
x
|
||||
},
|
||||
1 => {
|
||||
m!(bar);
|
||||
x
|
||||
},
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
let _ = match 0 {
|
||||
0 => {
|
||||
m!(foo);
|
||||
0
|
||||
},
|
||||
1 => {
|
||||
m!(bar);
|
||||
0
|
||||
},
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
let _ = match 0 {
|
||||
0 => {
|
||||
let mut x = 0;
|
||||
#[cfg(not_enabled)]
|
||||
{
|
||||
x = 5;
|
||||
}
|
||||
#[cfg(not(not_enabled))]
|
||||
{
|
||||
x = 6;
|
||||
}
|
||||
x
|
||||
},
|
||||
1 => {
|
||||
let mut x = 0;
|
||||
#[cfg(also_not_enabled)]
|
||||
{
|
||||
x = 5;
|
||||
}
|
||||
#[cfg(not(also_not_enabled))]
|
||||
{
|
||||
x = 6;
|
||||
}
|
||||
x
|
||||
},
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
let _ = match 0 {
|
||||
0 => foo!(),
|
||||
1 => bar!(),
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
let _ = match 0 {
|
||||
0 => cfg!(not_enabled),
|
||||
1 => cfg!(also_not_enabled),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//@no-rustfix: overlapping suggestions
|
||||
#![allow(clippy::manual_range_patterns)]
|
||||
#![warn(clippy::match_same_arms)]
|
||||
|
||||
pub enum Abc {
|
||||
|
|
@ -10,9 +10,17 @@ pub enum Abc {
|
|||
fn match_same_arms() {
|
||||
let _ = match Abc::A {
|
||||
Abc::A => 0,
|
||||
//~^ match_same_arms
|
||||
Abc::B => 1,
|
||||
_ => 0,
|
||||
//~^ match_same_arms
|
||||
};
|
||||
|
||||
match 0 {
|
||||
1 => 'a',
|
||||
2 => 'b',
|
||||
3 => 'b',
|
||||
_ => 'b',
|
||||
//~^ match_same_arms
|
||||
};
|
||||
|
||||
match (1, 2, 3) {
|
||||
|
|
@ -24,8 +32,8 @@ fn match_same_arms() {
|
|||
|
||||
let _ = match 42 {
|
||||
42 => 1,
|
||||
51 => 1,
|
||||
//~^ match_same_arms
|
||||
51 => 1,
|
||||
41 => 2,
|
||||
//~^ match_same_arms
|
||||
52 => 2,
|
||||
|
|
@ -34,11 +42,9 @@ fn match_same_arms() {
|
|||
|
||||
let _ = match 42 {
|
||||
1 => 2,
|
||||
//~^ match_same_arms
|
||||
2 => 2,
|
||||
//~^ match_same_arms
|
||||
//~| match_same_arms
|
||||
3 => 2,
|
||||
//~^ match_same_arms
|
||||
4 => 3,
|
||||
_ => 0,
|
||||
};
|
||||
|
|
@ -55,8 +61,8 @@ mod issue4244 {
|
|||
pub fn name(&self) -> String {
|
||||
match self {
|
||||
CommandInfo::BuiltIn { name, .. } => name.to_string(),
|
||||
CommandInfo::External { name, .. } => name.to_string(),
|
||||
//~^ match_same_arms
|
||||
CommandInfo::External { name, .. } => name.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,118 +1,121 @@
|
|||
error: this match arm has an identical body to the `_` wildcard arm
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:12:9
|
||||
|
|
||||
LL | / Abc::A => 0,
|
||||
LL | |
|
||||
| |________^ help: try removing the arm
|
||||
|
|
||||
= help: or try changing either arm body
|
||||
note: `_` wildcard arm here
|
||||
--> tests/ui/match_same_arms.rs:15:9
|
||||
|
|
||||
LL | Abc::A => 0,
|
||||
| ^^^^^^^^^^^
|
||||
LL | Abc::B => 1,
|
||||
LL | _ => 0,
|
||||
| ^^^^^^
|
||||
| ^^^^^^ the wildcard arm
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
= note: `-D clippy::match-same-arms` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]`
|
||||
help: otherwise remove the non-wildcard arm
|
||||
|
|
||||
LL - Abc::A => 0,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:19:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:20:9
|
||||
|
|
||||
LL | 2 => 'b',
|
||||
| ^^^^^^^^
|
||||
LL | 3 => 'b',
|
||||
| ^^^^^^^^
|
||||
LL | _ => 'b',
|
||||
| ^^^^^^^^ the wildcard arm
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise remove the non-wildcard arms
|
||||
|
|
||||
LL - 2 => 'b',
|
||||
LL - 3 => 'b',
|
||||
LL + _ => 'b',
|
||||
|
|
||||
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:27:9
|
||||
|
|
||||
LL | (1, .., 3) => 42,
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | (.., 3) => 42,
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ (1, .., 3) | (.., 3) => 42,
|
||||
LL |
|
||||
LL ~ _ => 0,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:27:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:34:9
|
||||
|
|
||||
LL | 42 => 1,
|
||||
| ^^^^^^^
|
||||
LL |
|
||||
LL | 51 => 1,
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - 42 => 1,
|
||||
LL - 51 => 1,
|
||||
LL + 51 | 42 => 1,
|
||||
LL ~
|
||||
LL ~ 42 | 51 => 1,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:29:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:37:9
|
||||
|
|
||||
LL | 41 => 2,
|
||||
| ^^^^^^^
|
||||
LL |
|
||||
LL | 52 => 2,
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ 41 | 52 => 2,
|
||||
LL |
|
||||
LL ~ _ => 0,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:37:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:44:9
|
||||
|
|
||||
LL | 1 => 2,
|
||||
| ^^^^^^
|
||||
LL |
|
||||
LL | 2 => 2,
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
|
|
||||
LL - 1 => 2,
|
||||
LL - 2 => 2,
|
||||
LL + 2 | 1 => 2,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:40:9
|
||||
|
|
||||
LL | 3 => 2,
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ 2 => 2,
|
||||
LL |
|
||||
LL |
|
||||
LL ~ 3 | 1 => 2,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:37:9
|
||||
|
|
||||
LL | 2 => 2,
|
||||
| ^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
|
|
||||
LL ~ 2 | 3 => 2,
|
||||
LL |
|
||||
LL |
|
||||
LL ~
|
||||
LL ~ 1 | 2 | 3 => 2,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms.rs:58:17
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms.rs:63:17
|
||||
|
|
||||
LL | CommandInfo::BuiltIn { name, .. } => name.to_string(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | CommandInfo::External { name, .. } => name.to_string(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - CommandInfo::BuiltIn { name, .. } => name.to_string(),
|
||||
LL - CommandInfo::External { name, .. } => name.to_string(),
|
||||
LL + CommandInfo::External { name, .. } | CommandInfo::BuiltIn { name, .. } => name.to_string(),
|
||||
LL ~
|
||||
LL ~ CommandInfo::BuiltIn { name, .. } | CommandInfo::External { name, .. } => name.to_string(),
|
||||
|
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ fn foo() -> bool {
|
|||
|
||||
fn match_same_arms() {
|
||||
let _ = match 42 {
|
||||
//~^^^^^^^^^ match_same_arms
|
||||
//~v match_same_arms
|
||||
_ => {
|
||||
foo();
|
||||
let mut a = 42 + [23].len() as i32;
|
||||
|
|
@ -27,14 +27,14 @@ fn match_same_arms() {
|
|||
};
|
||||
|
||||
let _ = match 42 {
|
||||
51 | 42 => foo(),
|
||||
//~^ match_same_arms
|
||||
42 | 51 => foo(),
|
||||
_ => true,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
None | Some(_) => 24,
|
||||
//~^ match_same_arms
|
||||
Some(_) | None => 24,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
|
|
@ -55,8 +55,8 @@ fn match_same_arms() {
|
|||
};
|
||||
|
||||
match (Some(42), Some(42)) {
|
||||
(None, Some(a)) | (Some(a), None) => bar(a),
|
||||
//~^ match_same_arms
|
||||
(Some(a), None) | (None, Some(a)) => bar(a),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +69,8 @@ fn match_same_arms() {
|
|||
};
|
||||
|
||||
let _ = match (Some(42), Some(42)) {
|
||||
(None, Some(a)) | (Some(a), None) if a == 42 => a,
|
||||
//~^ match_same_arms
|
||||
(Some(a), None) | (None, Some(a)) if a == 42 => a,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
|
|
@ -124,8 +124,8 @@ fn match_same_arms() {
|
|||
// False negative #2251.
|
||||
match x {
|
||||
Ok(_tmp) => println!("ok"),
|
||||
Ok(_) | Ok(3) => println!("ok"),
|
||||
//~^ match_same_arms
|
||||
Ok(3) | Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
unreachable!();
|
||||
},
|
||||
|
|
@ -149,10 +149,10 @@ fn match_same_arms() {
|
|||
|
||||
// still lint if the tokens are the same
|
||||
match 0 {
|
||||
1 | 0 => {
|
||||
//~^^^ match_same_arms
|
||||
0 | 1 => {
|
||||
empty!(0);
|
||||
},
|
||||
//~^^^ match_same_arms
|
||||
x => {
|
||||
empty!(x);
|
||||
},
|
||||
|
|
@ -208,9 +208,9 @@ fn main() {
|
|||
|
||||
// Suggest moving `Foo::X(0)` down.
|
||||
let _ = match Foo::X(0) {
|
||||
Foo::Y(_) | Foo::Z(0) => 2,
|
||||
Foo::Z(_) | Foo::X(0) => 1,
|
||||
//~^ match_same_arms
|
||||
Foo::Y(_) | Foo::Z(0) => 2,
|
||||
Foo::X(0) | Foo::Z(_) => 1,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
|
|
@ -230,10 +230,10 @@ fn main() {
|
|||
|
||||
// Lint.
|
||||
let _ = match None {
|
||||
//~^ match_same_arms
|
||||
Some(Bar { y: 10, z: 0, .. }) => 2,
|
||||
None => 50,
|
||||
Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1,
|
||||
//~^ match_same_arms
|
||||
Some(Bar { x: 0, y: 5, .. }) | Some(Bar { y: 0, x: 5, .. }) => 1,
|
||||
_ => 200,
|
||||
};
|
||||
|
||||
|
|
@ -246,8 +246,8 @@ fn main() {
|
|||
};
|
||||
|
||||
let _ = match 0 {
|
||||
1 | 0 => cfg!(not_enable),
|
||||
//~^ match_same_arms
|
||||
0 | 1 => cfg!(not_enable),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
|
@ -262,9 +262,34 @@ mod with_lifetime {
|
|||
impl<'a> MaybeStaticStr<'a> {
|
||||
fn get(&self) -> &'a str {
|
||||
match *self {
|
||||
MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s,
|
||||
//~^ match_same_arms
|
||||
MaybeStaticStr::Static(s) | MaybeStaticStr::Borrowed(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_levels() {
|
||||
match 1 {
|
||||
0 => "a",
|
||||
1 => "b",
|
||||
#[expect(clippy::match_same_arms)]
|
||||
_ => "b",
|
||||
};
|
||||
|
||||
match 2 {
|
||||
0 => "a",
|
||||
1 | 2 => "b",
|
||||
//~^ match_same_arms
|
||||
#[allow(clippy::match_same_arms)]
|
||||
_ => "b",
|
||||
};
|
||||
|
||||
match 3 {
|
||||
0 => "a",
|
||||
1 | 2 => "b",
|
||||
//~^ match_same_arms
|
||||
#[expect(clippy::match_same_arms)]
|
||||
_ => "b",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn match_same_arms() {
|
|||
a = -31 - a;
|
||||
a
|
||||
},
|
||||
//~^^^^^^^^^ match_same_arms
|
||||
//~v match_same_arms
|
||||
_ => {
|
||||
foo();
|
||||
let mut a = 42 + [23].len() as i32;
|
||||
|
|
@ -37,15 +37,15 @@ fn match_same_arms() {
|
|||
|
||||
let _ = match 42 {
|
||||
42 => foo(),
|
||||
51 => foo(),
|
||||
//~^ match_same_arms
|
||||
51 => foo(),
|
||||
_ => true,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
Some(_) => 24,
|
||||
None => 24,
|
||||
//~^ match_same_arms
|
||||
None => 24,
|
||||
};
|
||||
|
||||
let _ = match Some(42) {
|
||||
|
|
@ -67,8 +67,8 @@ fn match_same_arms() {
|
|||
|
||||
match (Some(42), Some(42)) {
|
||||
(Some(a), None) => bar(a),
|
||||
(None, Some(a)) => bar(a),
|
||||
//~^ match_same_arms
|
||||
(None, Some(a)) => bar(a),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
|
@ -82,8 +82,8 @@ fn match_same_arms() {
|
|||
|
||||
let _ = match (Some(42), Some(42)) {
|
||||
(Some(a), None) if a == 42 => a,
|
||||
(None, Some(a)) if a == 42 => a,
|
||||
//~^ match_same_arms
|
||||
(None, Some(a)) if a == 42 => a,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
|
|
@ -140,8 +140,8 @@ fn match_same_arms() {
|
|||
match x {
|
||||
Ok(_tmp) => println!("ok"),
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
//~^ match_same_arms
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
unreachable!();
|
||||
},
|
||||
|
|
@ -168,10 +168,10 @@ fn match_same_arms() {
|
|||
0 => {
|
||||
empty!(0);
|
||||
},
|
||||
//~^^^ match_same_arms
|
||||
1 => {
|
||||
empty!(0);
|
||||
},
|
||||
//~^^^ match_same_arms
|
||||
x => {
|
||||
empty!(x);
|
||||
},
|
||||
|
|
@ -229,9 +229,9 @@ fn main() {
|
|||
// Suggest moving `Foo::X(0)` down.
|
||||
let _ = match Foo::X(0) {
|
||||
Foo::X(0) => 1,
|
||||
//~^ match_same_arms
|
||||
Foo::Y(_) | Foo::Z(0) => 2,
|
||||
Foo::Z(_) => 1,
|
||||
//~^ match_same_arms
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
|
|
@ -252,10 +252,10 @@ fn main() {
|
|||
// Lint.
|
||||
let _ = match None {
|
||||
Some(Bar { x: 0, y: 5, .. }) => 1,
|
||||
//~^ match_same_arms
|
||||
Some(Bar { y: 10, z: 0, .. }) => 2,
|
||||
None => 50,
|
||||
Some(Bar { y: 0, x: 5, .. }) => 1,
|
||||
//~^ match_same_arms
|
||||
_ => 200,
|
||||
};
|
||||
|
||||
|
|
@ -269,8 +269,8 @@ fn main() {
|
|||
|
||||
let _ = match 0 {
|
||||
0 => cfg!(not_enable),
|
||||
1 => cfg!(not_enable),
|
||||
//~^ match_same_arms
|
||||
1 => cfg!(not_enable),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
|
@ -286,9 +286,36 @@ mod with_lifetime {
|
|||
fn get(&self) -> &'a str {
|
||||
match *self {
|
||||
MaybeStaticStr::Static(s) => s,
|
||||
MaybeStaticStr::Borrowed(s) => s,
|
||||
//~^ match_same_arms
|
||||
MaybeStaticStr::Borrowed(s) => s,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_levels() {
|
||||
match 1 {
|
||||
0 => "a",
|
||||
1 => "b",
|
||||
#[expect(clippy::match_same_arms)]
|
||||
_ => "b",
|
||||
};
|
||||
|
||||
match 2 {
|
||||
0 => "a",
|
||||
1 => "b",
|
||||
//~^ match_same_arms
|
||||
2 => "b",
|
||||
#[allow(clippy::match_same_arms)]
|
||||
_ => "b",
|
||||
};
|
||||
|
||||
match 3 {
|
||||
0 => "a",
|
||||
1 => "b",
|
||||
//~^ match_same_arms
|
||||
2 => "b",
|
||||
#[expect(clippy::match_same_arms)]
|
||||
_ => "b",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error: this match arm has an identical body to the `_` wildcard arm
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:17:9
|
||||
|
|
||||
LL | / 42 => {
|
||||
|
|
@ -6,14 +6,10 @@ LL | | foo();
|
|||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
LL | | if true {
|
||||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
LL | |
|
||||
| |________^ help: try removing the arm
|
||||
|
|
||||
= help: or try changing either arm body
|
||||
note: `_` wildcard arm here
|
||||
--> tests/ui/match_same_arms2.rs:27:9
|
||||
|
|
||||
| |_________^
|
||||
LL |
|
||||
LL | / _ => {
|
||||
LL | | foo();
|
||||
LL | | let mut a = 42 + [23].len() as i32;
|
||||
|
|
@ -21,134 +17,169 @@ LL | | if true {
|
|||
... |
|
||||
LL | | a
|
||||
LL | | },
|
||||
| |_________^
|
||||
| |_________^ the wildcard arm
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
= note: `-D clippy::match-same-arms` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]`
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:40:9
|
||||
help: otherwise remove the non-wildcard arm
|
||||
|
|
||||
LL - 42 => {
|
||||
LL - foo();
|
||||
LL - let mut a = 42 + [23].len() as i32;
|
||||
LL - if true {
|
||||
LL - a += 7;
|
||||
LL - }
|
||||
LL - a = -31 - a;
|
||||
LL - a
|
||||
LL - },
|
||||
|
|
||||
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:39:9
|
||||
|
|
||||
LL | 42 => foo(),
|
||||
| ^^^^^^^^^^^
|
||||
LL |
|
||||
LL | 51 => foo(),
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - 42 => foo(),
|
||||
LL - 51 => foo(),
|
||||
LL + 51 | 42 => foo(),
|
||||
LL ~
|
||||
LL ~ 42 | 51 => foo(),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:47:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:46:9
|
||||
|
|
||||
LL | Some(_) => 24,
|
||||
| ^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | None => 24,
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - Some(_) => 24,
|
||||
LL - None => 24,
|
||||
LL + None | Some(_) => 24,
|
||||
LL ~
|
||||
LL ~ Some(_) | None => 24,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:70:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:69:9
|
||||
|
|
||||
LL | (Some(a), None) => bar(a),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | (None, Some(a)) => bar(a),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - (Some(a), None) => bar(a),
|
||||
LL - (None, Some(a)) => bar(a),
|
||||
LL + (None, Some(a)) | (Some(a), None) => bar(a),
|
||||
LL ~
|
||||
LL ~ (Some(a), None) | (None, Some(a)) => bar(a),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:85:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:84:9
|
||||
|
|
||||
LL | (Some(a), None) if a == 42 => a,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | (None, Some(a)) if a == 42 => a,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - (Some(a), None) if a == 42 => a,
|
||||
LL - (None, Some(a)) if a == 42 => a,
|
||||
LL + (None, Some(a)) | (Some(a), None) if a == 42 => a,
|
||||
LL ~
|
||||
LL ~ (Some(a), None) | (None, Some(a)) if a == 42 => a,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:91:9
|
||||
|
|
||||
LL | (Some(a), ..) => bar(a),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | (.., Some(a)) => bar(a),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ (Some(a), ..) | (.., Some(a)) => bar(a),
|
||||
LL |
|
||||
LL ~ _ => (),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:126:9
|
||||
|
|
||||
LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | (Ok(_), Some(x)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x),
|
||||
LL |
|
||||
LL ~ _ => println!("err"),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:143:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:142:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - Ok(3) => println!("ok"),
|
||||
LL - Ok(_) => println!("ok"),
|
||||
LL + Ok(_) | Ok(3) => println!("ok"),
|
||||
LL ~
|
||||
LL ~ Ok(3) | Ok(_) => println!("ok"),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:171:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:168:9
|
||||
|
|
||||
LL | / 0 => {
|
||||
LL | | empty!(0);
|
||||
LL | | },
|
||||
| |_________^
|
||||
LL |
|
||||
LL | / 1 => {
|
||||
LL | | empty!(0);
|
||||
LL | | },
|
||||
| |_________^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - 0 => {
|
||||
LL - empty!(0);
|
||||
LL - },
|
||||
LL - 1 => {
|
||||
LL + 1 | 0 => {
|
||||
LL ~
|
||||
LL ~ 0 | 1 => {
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:222:9
|
||||
|
|
||||
LL | Foo::X(0) => 1,
|
||||
| ^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | Foo::Z(_) => 1,
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ Foo::X(0) | Foo::Z(_) => 1,
|
||||
LL |
|
||||
|
|
@ -156,60 +187,106 @@ LL | Foo::X(_) | Foo::Y(_) => 2,
|
|||
LL ~ _ => 0,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:233:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:231:9
|
||||
|
|
||||
LL | Foo::X(0) => 1,
|
||||
| ^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | Foo::Z(_) => 1,
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ Foo::Y(_) | Foo::Z(0) => 2,
|
||||
LL ~ Foo::Z(_) | Foo::X(0) => 1,
|
||||
LL ~
|
||||
LL | Foo::Y(_) | Foo::Z(0) => 2,
|
||||
LL ~ Foo::X(0) | Foo::Z(_) => 1,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:257:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:254:9
|
||||
|
|
||||
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | Some(Bar { y: 0, x: 5, .. }) => 1,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ Some(Bar { y: 10, z: 0, .. }) => 2,
|
||||
LL ~
|
||||
LL | Some(Bar { y: 10, z: 0, .. }) => 2,
|
||||
LL | None => 50,
|
||||
LL ~ Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1,
|
||||
LL ~ Some(Bar { x: 0, y: 5, .. }) | Some(Bar { y: 0, x: 5, .. }) => 1,
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:272:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:271:9
|
||||
|
|
||||
LL | 0 => cfg!(not_enable),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | 1 => cfg!(not_enable),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - 0 => cfg!(not_enable),
|
||||
LL - 1 => cfg!(not_enable),
|
||||
LL + 1 | 0 => cfg!(not_enable),
|
||||
LL ~
|
||||
LL ~ 0 | 1 => cfg!(not_enable),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to another arm
|
||||
--> tests/ui/match_same_arms2.rs:289:17
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:288:17
|
||||
|
|
||||
LL | MaybeStaticStr::Static(s) => s,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | MaybeStaticStr::Borrowed(s) => s,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try changing either arm body
|
||||
help: or try merging the arm patterns and removing the obsolete arm
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL - MaybeStaticStr::Static(s) => s,
|
||||
LL - MaybeStaticStr::Borrowed(s) => s,
|
||||
LL + MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s,
|
||||
LL ~
|
||||
LL ~ MaybeStaticStr::Static(s) | MaybeStaticStr::Borrowed(s) => s,
|
||||
|
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:306:9
|
||||
|
|
||||
LL | 1 => "b",
|
||||
| ^^^^^^^^
|
||||
LL |
|
||||
LL | 2 => "b",
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ 1 | 2 => "b",
|
||||
LL |
|
||||
LL ~ #[allow(clippy::match_same_arms)]
|
||||
|
|
||||
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms2.rs:315:9
|
||||
|
|
||||
LL | 1 => "b",
|
||||
| ^^^^^^^^
|
||||
LL |
|
||||
LL | 2 => "b",
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~ 1 | 2 => "b",
|
||||
LL |
|
||||
LL ~ #[expect(clippy::match_same_arms)]
|
||||
|
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -7,14 +7,22 @@ fn repeat() -> ! {
|
|||
panic!()
|
||||
}
|
||||
|
||||
#[deny(non_exhaustive_omitted_patterns)]
|
||||
pub fn f(x: Ordering) {
|
||||
#[deny(non_exhaustive_omitted_patterns)]
|
||||
match x {
|
||||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
_ => repeat(),
|
||||
//~^ match_same_arms
|
||||
Ordering::AcqRel | Ordering::SeqCst | _ => repeat(),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
//~^ match_same_arms
|
||||
Ordering::AcqRel | Ordering::SeqCst | _ => repeat(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -28,21 +36,21 @@ mod f {
|
|||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
_ => repeat(),
|
||||
//~^ match_same_arms
|
||||
Ordering::AcqRel | Ordering::SeqCst | _ => repeat(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Below should still lint
|
||||
// Below can still suggest removing the other patterns
|
||||
|
||||
pub fn g(x: Ordering) {
|
||||
match x {
|
||||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
//~^ match_same_arms
|
||||
_ => repeat(),
|
||||
//~^ match_same_arms
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,8 +62,8 @@ mod g {
|
|||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
//~^ match_same_arms
|
||||
_ => repeat(),
|
||||
//~^ match_same_arms
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,25 @@ fn repeat() -> ! {
|
|||
panic!()
|
||||
}
|
||||
|
||||
#[deny(non_exhaustive_omitted_patterns)]
|
||||
pub fn f(x: Ordering) {
|
||||
#[deny(non_exhaustive_omitted_patterns)]
|
||||
match x {
|
||||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
//~^ match_same_arms
|
||||
_ => repeat(),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ordering::Relaxed => println!("relaxed"),
|
||||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel => repeat(),
|
||||
//~^ match_same_arms
|
||||
Ordering::SeqCst | _ => repeat(),
|
||||
}
|
||||
}
|
||||
|
||||
mod f {
|
||||
|
|
@ -29,12 +39,13 @@ mod f {
|
|||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
//~^ match_same_arms
|
||||
_ => repeat(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Below should still lint
|
||||
// Below can still suggest removing the other patterns
|
||||
|
||||
pub fn g(x: Ordering) {
|
||||
match x {
|
||||
|
|
@ -42,8 +53,8 @@ pub fn g(x: Ordering) {
|
|||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
//~^ match_same_arms
|
||||
_ => repeat(),
|
||||
//~^ match_same_arms
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,8 +67,8 @@ mod g {
|
|||
Ordering::Release => println!("release"),
|
||||
Ordering::Acquire => println!("acquire"),
|
||||
Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
//~^ match_same_arms
|
||||
_ => repeat(),
|
||||
//~^ match_same_arms
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,80 @@
|
|||
error: this match arm has an identical body to the `_` wildcard arm
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:44:9
|
||||
|
|
||||
LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
LL | |
|
||||
| |________^ help: try removing the arm
|
||||
|
|
||||
= help: or try changing either arm body
|
||||
note: `_` wildcard arm here
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:46:9
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:16:9
|
||||
|
|
||||
LL | Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | _ => repeat(),
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
= note: `-D clippy::match-same-arms` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]`
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~
|
||||
LL ~ Ordering::AcqRel | Ordering::SeqCst | _ => repeat(),
|
||||
|
|
||||
|
||||
error: this match arm has an identical body to the `_` wildcard arm
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:58:13
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:25:9
|
||||
|
|
||||
LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
LL | |
|
||||
| |____________^ help: try removing the arm
|
||||
LL | Ordering::AcqRel => repeat(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | Ordering::SeqCst | _ => repeat(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: or try changing either arm body
|
||||
note: `_` wildcard arm here
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:60:13
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~
|
||||
LL ~ Ordering::AcqRel | Ordering::SeqCst | _ => repeat(),
|
||||
|
|
||||
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:41:13
|
||||
|
|
||||
LL | Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | _ => repeat(),
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise merge the patterns into a single arm
|
||||
|
|
||||
LL ~
|
||||
LL ~ Ordering::AcqRel | Ordering::SeqCst | _ => repeat(),
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:55:9
|
||||
|
|
||||
LL | Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | _ => repeat(),
|
||||
| ^^^^^^^^^^^^^ the wildcard arm
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise remove the non-wildcard arm
|
||||
|
|
||||
LL - Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
|
|
||||
|
||||
error: these match arms have identical bodies
|
||||
--> tests/ui/match_same_arms_non_exhaustive.rs:69:13
|
||||
|
|
||||
LL | Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | _ => repeat(),
|
||||
| ^^^^^^^^^^^^^ the wildcard arm
|
||||
|
|
||||
= help: if this is unintentional make the arms return different values
|
||||
help: otherwise remove the non-wildcard arm
|
||||
|
|
||||
LL - Ordering::AcqRel | Ordering::SeqCst => repeat(),
|
||||
|
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -31,34 +31,34 @@ fn ifs_same_cond_fn() {
|
|||
let obj = Struct;
|
||||
|
||||
if function() {
|
||||
} else if function() {
|
||||
//~^ same_functions_in_if_condition
|
||||
} else if function() {
|
||||
}
|
||||
|
||||
if fn_arg(a) {
|
||||
} else if fn_arg(a) {
|
||||
//~^ same_functions_in_if_condition
|
||||
} else if fn_arg(a) {
|
||||
}
|
||||
|
||||
if obj.method() {
|
||||
} else if obj.method() {
|
||||
//~^ same_functions_in_if_condition
|
||||
} else if obj.method() {
|
||||
}
|
||||
|
||||
if obj.method_arg(a) {
|
||||
} else if obj.method_arg(a) {
|
||||
//~^ same_functions_in_if_condition
|
||||
} else if obj.method_arg(a) {
|
||||
}
|
||||
|
||||
let mut v = vec![1];
|
||||
if v.pop().is_none() {
|
||||
} else if v.pop().is_none() {
|
||||
//~^ same_functions_in_if_condition
|
||||
} else if v.pop().is_none() {
|
||||
}
|
||||
|
||||
if v.len() == 42 {
|
||||
} else if v.len() == 42 {
|
||||
//~^ same_functions_in_if_condition
|
||||
} else if v.len() == 42 {
|
||||
}
|
||||
|
||||
if v.len() == 1 {
|
||||
|
|
|
|||
|
|
@ -1,79 +1,62 @@
|
|||
error: this `if` has the same function call as a previous `if`
|
||||
--> tests/ui/same_functions_in_if_condition.rs:34:15
|
||||
|
|
||||
LL | } else if function() {
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same function call
|
||||
--> tests/ui/same_functions_in_if_condition.rs:33:8
|
||||
|
|
||||
LL | if function() {
|
||||
| ^^^^^^^^^^
|
||||
LL |
|
||||
LL | } else if function() {
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> tests/ui/same_functions_in_if_condition.rs:2:9
|
||||
|
|
||||
LL | #![deny(clippy::same_functions_in_if_condition)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `if` has the same function call as a previous `if`
|
||||
--> tests/ui/same_functions_in_if_condition.rs:39:15
|
||||
|
|
||||
LL | } else if fn_arg(a) {
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same function call
|
||||
--> tests/ui/same_functions_in_if_condition.rs:38:8
|
||||
|
|
||||
LL | if fn_arg(a) {
|
||||
| ^^^^^^^^^
|
||||
LL |
|
||||
LL | } else if fn_arg(a) {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: this `if` has the same function call as a previous `if`
|
||||
--> tests/ui/same_functions_in_if_condition.rs:44:15
|
||||
|
|
||||
LL | } else if obj.method() {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same function call
|
||||
--> tests/ui/same_functions_in_if_condition.rs:43:8
|
||||
|
|
||||
LL | if obj.method() {
|
||||
| ^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | } else if obj.method() {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: this `if` has the same function call as a previous `if`
|
||||
--> tests/ui/same_functions_in_if_condition.rs:49:15
|
||||
|
|
||||
LL | } else if obj.method_arg(a) {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same function call
|
||||
--> tests/ui/same_functions_in_if_condition.rs:48:8
|
||||
|
|
||||
LL | if obj.method_arg(a) {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `if` has the same function call as a previous `if`
|
||||
--> tests/ui/same_functions_in_if_condition.rs:55:15
|
||||
|
|
||||
LL | } else if v.pop().is_none() {
|
||||
LL |
|
||||
LL | } else if obj.method_arg(a) {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
|
||||
error: these `if` branches have the same function call
|
||||
--> tests/ui/same_functions_in_if_condition.rs:54:8
|
||||
|
|
||||
LL | if v.pop().is_none() {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | } else if v.pop().is_none() {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: this `if` has the same function call as a previous `if`
|
||||
--> tests/ui/same_functions_in_if_condition.rs:60:15
|
||||
|
|
||||
LL | } else if v.len() == 42 {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
error: these `if` branches have the same function call
|
||||
--> tests/ui/same_functions_in_if_condition.rs:59:8
|
||||
|
|
||||
LL | if v.len() == 42 {
|
||||
| ^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | } else if v.len() == 42 {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue