2018-07-28 17:34:52 +02:00
|
|
|
#![warn(clippy::short_circuit_statement)]
|
2019-08-22 07:18:08 +02:00
|
|
|
#![allow(clippy::nonminimal_bool)]
|
2016-12-30 00:00:55 +01:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
f() && g();
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
|
|
|
|
|
2016-12-30 00:00:55 +01:00
|
|
|
f() || g();
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
|
|
|
|
|
2016-12-30 00:00:55 +01:00
|
|
|
1 == 2 || g();
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
|
|
|
|
|
2025-01-28 19:22:55 +01:00
|
|
|
(f() || g()) && (H * 2);
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
|
|
|
|
|
2025-01-28 19:22:55 +01:00
|
|
|
(f() || g()) || (H * 2);
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
2025-01-28 19:22:55 +01:00
|
|
|
|
|
|
|
|
macro_rules! mac {
|
|
|
|
|
($f:ident or $g:ident) => {
|
|
|
|
|
$f() || $g()
|
|
|
|
|
};
|
|
|
|
|
($f:ident and $g:ident) => {
|
|
|
|
|
$f() && $g()
|
|
|
|
|
};
|
|
|
|
|
() => {
|
|
|
|
|
f() && g()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mac!() && mac!();
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
|
|
|
|
|
2025-01-28 19:22:55 +01:00
|
|
|
mac!() || mac!();
|
2025-02-28 23:20:48 +01:00
|
|
|
//~^ short_circuit_statement
|
2025-01-28 19:22:55 +01:00
|
|
|
|
|
|
|
|
// Do not lint if the expression comes from a macro
|
|
|
|
|
mac!();
|
2016-12-30 00:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn f() -> bool {
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn g() -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
2025-01-28 19:22:55 +01:00
|
|
|
|
|
|
|
|
struct H;
|
|
|
|
|
|
|
|
|
|
impl std::ops::Mul<u32> for H {
|
|
|
|
|
type Output = bool;
|
|
|
|
|
fn mul(self, other: u32) -> Self::Output {
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
}
|