2019-01-02 00:59:48 -06:00
|
|
|
#![warn(clippy::ifs_same_cond)]
|
2023-06-10 06:43:30 -05:00
|
|
|
#![allow(
|
|
|
|
clippy::if_same_then_else,
|
|
|
|
clippy::comparison_chain,
|
|
|
|
clippy::needless_if,
|
|
|
|
clippy::needless_else
|
|
|
|
)] // all empty blocks
|
2019-01-02 00:59:48 -06:00
|
|
|
|
|
|
|
fn ifs_same_cond() {
|
|
|
|
let a = 0;
|
|
|
|
let b = false;
|
|
|
|
|
|
|
|
if b {
|
|
|
|
} else if b {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: this `if` has the same condition as a previous `if`
|
2019-01-02 00:59:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if a == 1 {
|
|
|
|
} else if a == 1 {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: this `if` has the same condition as a previous `if`
|
2019-01-02 00:59:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if 2 * a == 1 {
|
|
|
|
} else if 2 * a == 2 {
|
|
|
|
} else if 2 * a == 1 {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: this `if` has the same condition as a previous `if`
|
2019-01-02 00:59:48 -06:00
|
|
|
} else if a == 1 {
|
|
|
|
}
|
|
|
|
|
|
|
|
// See #659
|
|
|
|
if cfg!(feature = "feature1-659") {
|
|
|
|
1
|
|
|
|
} else if cfg!(feature = "feature2-659") {
|
|
|
|
2
|
|
|
|
} else {
|
|
|
|
3
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut v = vec![1];
|
2022-08-03 15:13:06 -05:00
|
|
|
if v.pop().is_none() {
|
2019-01-02 00:59:48 -06:00
|
|
|
// ok, functions
|
2022-08-03 15:13:06 -05:00
|
|
|
} else if v.pop().is_none() {
|
2019-01-02 00:59:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if v.len() == 42 {
|
|
|
|
// ok, functions
|
|
|
|
} else if v.len() == 42 {
|
|
|
|
}
|
2023-07-20 04:49:27 -05:00
|
|
|
|
|
|
|
if let Some(env1) = option_env!("ENV1") {
|
|
|
|
} else if let Some(env2) = option_env!("ENV2") {
|
|
|
|
}
|
2019-01-02 00:59:48 -06:00
|
|
|
}
|
|
|
|
|
2023-02-16 03:47:28 -06:00
|
|
|
fn issue10272() {
|
|
|
|
let a = String::from("ha");
|
|
|
|
if a.contains("ah") {
|
|
|
|
} else if a.contains("ah") {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: this `if` has the same condition as a previous `if`
|
2023-02-16 03:47:28 -06:00
|
|
|
// Trigger this lint
|
|
|
|
} else if a.contains("ha") {
|
|
|
|
} else if a == "wow" {
|
|
|
|
}
|
2023-02-23 20:46:07 -06:00
|
|
|
|
|
|
|
let p: *mut i8 = std::ptr::null_mut();
|
|
|
|
if p.is_null() {
|
|
|
|
} else if p.align_offset(0) == 0 {
|
|
|
|
} else if p.is_null() {
|
|
|
|
// ok, p is mutable pointer
|
|
|
|
} else {
|
|
|
|
}
|
2023-03-13 07:17:30 -05:00
|
|
|
|
|
|
|
let x = std::cell::Cell::new(true);
|
|
|
|
if x.get() {
|
|
|
|
} else if !x.take() {
|
|
|
|
} else if x.get() {
|
|
|
|
// ok, x is interior mutable type
|
|
|
|
} else {
|
|
|
|
}
|
2023-02-16 03:47:28 -06:00
|
|
|
}
|
|
|
|
|
2019-01-02 00:59:48 -06:00
|
|
|
fn main() {}
|