2023-07-27 11:40:22 +00:00
|
|
|
//@no-rustfix: overlapping suggestions
|
2022-06-25 12:16:30 +00:00
|
|
|
#![feature(lint_reasons)]
|
2023-12-16 16:40:32 +00:00
|
|
|
#![allow(
|
|
|
|
unused,
|
|
|
|
clippy::diverging_sub_expression,
|
|
|
|
clippy::needless_if,
|
|
|
|
clippy::redundant_pattern_matching
|
|
|
|
)]
|
2020-01-13 22:41:11 +00:00
|
|
|
#![warn(clippy::nonminimal_bool)]
|
2023-06-06 20:56:57 +00:00
|
|
|
#![allow(clippy::useless_vec)]
|
2020-01-13 22:41:11 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a: bool = unimplemented!();
|
|
|
|
let b: bool = unimplemented!();
|
|
|
|
let c: bool = unimplemented!();
|
|
|
|
let d: bool = unimplemented!();
|
|
|
|
let e: bool = unimplemented!();
|
|
|
|
let _ = !true;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
|
|
|
//~| NOTE: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = !false;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = !!a;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = false || a;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
// don't lint on cfgs
|
|
|
|
let _ = cfg!(you_shall_not_not_pass) && a;
|
|
|
|
let _ = a || !b || !c || !d || !e;
|
|
|
|
let _ = !(!a && b);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = !(!a || b);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = !a && !(b && c);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn equality_stuff() {
|
|
|
|
let a: i32 = unimplemented!();
|
|
|
|
let b: i32 = unimplemented!();
|
|
|
|
let c: i32 = unimplemented!();
|
|
|
|
let d: i32 = unimplemented!();
|
|
|
|
let _ = a == b && c == 5 && a == b;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = a == b || c == 5 || a == b;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = a == b && c == 5 && b == a;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = a != b || !(a != b || c == d);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
let _ = a != b && !(a != b && c == d);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2020-01-13 22:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue3847(a: u32, b: u32) -> bool {
|
|
|
|
const THRESHOLD: u32 = 1_000;
|
|
|
|
|
|
|
|
if a < THRESHOLD && b >= THRESHOLD || a >= THRESHOLD && b < THRESHOLD {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue4548() {
|
|
|
|
fn f(_i: u32, _j: u32) -> u32 {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
let j = 0;
|
|
|
|
|
|
|
|
if i != j && f(i, j) != 0 || i == j && f(i, j) != 1 {}
|
|
|
|
}
|
2022-06-25 12:16:30 +00:00
|
|
|
|
|
|
|
fn check_expect() {
|
|
|
|
let a: bool = unimplemented!();
|
2023-05-30 22:17:26 +00:00
|
|
|
#[expect(clippy::nonminimal_bool)]
|
2022-06-25 12:16:30 +00:00
|
|
|
let _ = !!a;
|
|
|
|
}
|
2022-09-10 17:48:14 +00:00
|
|
|
|
|
|
|
fn issue9428() {
|
|
|
|
if matches!(true, true) && true {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: this boolean expression can be simplified
|
2022-09-10 17:48:14 +00:00
|
|
|
println!("foo");
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 23:34:35 +00:00
|
|
|
|
|
|
|
fn issue_10523() {
|
|
|
|
macro_rules! a {
|
|
|
|
($v:expr) => {
|
|
|
|
$v.is_some()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let x: Option<u32> = None;
|
|
|
|
if !a!(x) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_10523_1() {
|
|
|
|
macro_rules! a {
|
|
|
|
($v:expr) => {
|
|
|
|
!$v.is_some()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
let x: Option<u32> = None;
|
|
|
|
if a!(x) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_10523_2() {
|
|
|
|
macro_rules! a {
|
|
|
|
() => {
|
|
|
|
!None::<u32>.is_some()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if a!() {}
|
|
|
|
}
|
2023-04-02 14:18:03 +00:00
|
|
|
|
|
|
|
fn issue_10435() {
|
|
|
|
let x = vec![0];
|
|
|
|
let y = vec![1];
|
|
|
|
let z = vec![2];
|
|
|
|
|
|
|
|
// vvv Should not lint
|
|
|
|
#[allow(clippy::nonminimal_bool)]
|
|
|
|
if !x.is_empty() && !(y.is_empty() || z.is_empty()) {
|
|
|
|
println!("{}", line!());
|
|
|
|
}
|
|
|
|
|
|
|
|
// vvv Should not lint (#10435 talks about a bug where it lints)
|
|
|
|
#[allow(clippy::nonminimal_bool)]
|
|
|
|
if !(x == [0]) {
|
|
|
|
println!("{}", line!());
|
|
|
|
}
|
|
|
|
}
|
2023-05-30 05:43:10 +00:00
|
|
|
|
|
|
|
fn issue10836() {
|
|
|
|
struct Foo(bool);
|
|
|
|
impl std::ops::Not for Foo {
|
|
|
|
type Output = bool;
|
|
|
|
|
|
|
|
fn not(self) -> Self::Output {
|
|
|
|
!self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not lint
|
|
|
|
let _: bool = !!Foo(true);
|
|
|
|
}
|
2024-01-06 06:12:41 +00:00
|
|
|
|
|
|
|
fn issue11932() {
|
|
|
|
let x: i32 = unimplemented!();
|
|
|
|
|
|
|
|
#[allow(clippy::nonminimal_bool)]
|
|
|
|
let _ = x % 2 == 0 || {
|
|
|
|
// Should not lint
|
|
|
|
assert!(x > 0);
|
|
|
|
x % 3 == 0
|
|
|
|
};
|
|
|
|
}
|
2024-02-08 21:36:41 +00:00
|
|
|
|
|
|
|
fn issue_5794() {
|
|
|
|
let a = 0;
|
|
|
|
if !(12 == a) {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if !(a == 12) {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if !(12 != a) {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if !(a != 12) {} //~ ERROR: this boolean expression can be simplified
|
2024-02-09 19:47:31 +00:00
|
|
|
|
|
|
|
let b = true;
|
|
|
|
let c = false;
|
|
|
|
if !b == true {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if !b != true {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if true == !b {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if true != !b {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if !b == !c {} //~ ERROR: this boolean expression can be simplified
|
|
|
|
if !b != !c {} //~ ERROR: this boolean expression can be simplified
|
2024-02-08 21:36:41 +00:00
|
|
|
}
|