2022-05-05 09:12:52 -05:00
|
|
|
#![feature(adt_const_params)]
|
2023-04-23 06:03:09 -05:00
|
|
|
#![deny(clippy::same_functions_in_if_condition)]
|
2022-10-06 02:44:38 -05:00
|
|
|
// ifs_same_cond warning is different from `ifs_same_cond`.
|
|
|
|
// clippy::if_same_then_else, clippy::comparison_chain -- all empty blocks
|
|
|
|
#![allow(incomplete_features)]
|
|
|
|
#![allow(
|
|
|
|
clippy::comparison_chain,
|
|
|
|
clippy::if_same_then_else,
|
|
|
|
clippy::ifs_same_cond,
|
|
|
|
clippy::uninlined_format_args
|
|
|
|
)]
|
2019-11-13 23:06:34 -06:00
|
|
|
|
2023-05-16 23:05:46 -05:00
|
|
|
use std::marker::ConstParamTy;
|
|
|
|
|
2019-11-13 23:06:34 -06:00
|
|
|
fn function() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fn_arg(_arg: u8) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Struct;
|
|
|
|
|
|
|
|
impl Struct {
|
|
|
|
fn method(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
fn method_arg(&self, _arg: u8) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ifs_same_cond_fn() {
|
|
|
|
let a = 0;
|
|
|
|
let obj = Struct;
|
|
|
|
|
|
|
|
if function() {
|
|
|
|
} else if function() {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: `if` has the same function call as a previous `if`
|
2019-11-13 23:06:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if fn_arg(a) {
|
|
|
|
} else if fn_arg(a) {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: `if` has the same function call as a previous `if`
|
2019-11-13 23:06:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if obj.method() {
|
|
|
|
} else if obj.method() {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: `if` has the same function call as a previous `if`
|
2019-11-13 23:06:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if obj.method_arg(a) {
|
|
|
|
} else if obj.method_arg(a) {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: `if` has the same function call as a previous `if`
|
2019-11-13 23:06:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut v = vec![1];
|
2022-08-11 12:42:16 -05:00
|
|
|
if v.pop().is_none() {
|
|
|
|
} else if v.pop().is_none() {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: `if` has the same function call as a previous `if`
|
2019-11-13 23:06:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if v.len() == 42 {
|
|
|
|
} else if v.len() == 42 {
|
2023-04-20 10:19:36 -05:00
|
|
|
//~^ ERROR: `if` has the same function call as a previous `if`
|
2019-11-13 23:06:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if v.len() == 1 {
|
|
|
|
// ok, different conditions
|
|
|
|
} else if v.len() == 2 {
|
|
|
|
}
|
|
|
|
|
|
|
|
if fn_arg(0) {
|
|
|
|
// ok, different arguments.
|
|
|
|
} else if fn_arg(1) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if obj.method_arg(0) {
|
|
|
|
// ok, different arguments.
|
|
|
|
} else if obj.method_arg(1) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if a == 1 {
|
|
|
|
// ok, warning is on `ifs_same_cond` behalf.
|
|
|
|
} else if a == 1 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 15:16:59 -05:00
|
|
|
fn main() {
|
|
|
|
// macro as condition (see #6168)
|
|
|
|
let os = if cfg!(target_os = "macos") {
|
|
|
|
"macos"
|
|
|
|
} else if cfg!(target_os = "windows") {
|
|
|
|
"windows"
|
|
|
|
} else {
|
|
|
|
"linux"
|
|
|
|
};
|
|
|
|
println!("{}", os);
|
2022-05-05 09:12:52 -05:00
|
|
|
|
2023-05-16 23:05:46 -05:00
|
|
|
#[derive(PartialEq, Eq, ConstParamTy)]
|
2022-05-05 09:12:52 -05:00
|
|
|
enum E {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
fn generic<const P: E>() -> bool {
|
|
|
|
match P {
|
|
|
|
E::A => true,
|
|
|
|
E::B => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if generic::<{ E::A }>() {
|
|
|
|
println!("A");
|
|
|
|
} else if generic::<{ E::B }>() {
|
|
|
|
println!("B");
|
|
|
|
}
|
2020-10-23 15:16:59 -05:00
|
|
|
}
|