2023-06-10 06:43:30 -05:00
|
|
|
//@run-rustfix
|
2023-04-20 10:19:36 -05:00
|
|
|
//@aux-build:proc_macros.rs:proc-macro
|
2023-06-11 06:50:03 -05:00
|
|
|
#![feature(let_chains)]
|
2023-06-10 06:43:30 -05:00
|
|
|
#![allow(
|
|
|
|
clippy::blocks_in_if_conditions,
|
|
|
|
clippy::if_same_then_else,
|
|
|
|
clippy::ifs_same_cond,
|
2023-06-12 10:05:14 -05:00
|
|
|
clippy::let_unit_value,
|
2023-06-10 06:43:30 -05:00
|
|
|
clippy::needless_else,
|
|
|
|
clippy::no_effect,
|
2023-06-11 06:50:03 -05:00
|
|
|
clippy::nonminimal_bool,
|
2023-06-12 10:05:14 -05:00
|
|
|
clippy::short_circuit_statement,
|
|
|
|
clippy::unnecessary_operation,
|
2023-06-10 06:43:30 -05:00
|
|
|
unused
|
|
|
|
)]
|
|
|
|
#![warn(clippy::needless_if)]
|
|
|
|
|
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::external;
|
|
|
|
use proc_macros::with_span;
|
|
|
|
|
2023-06-12 10:05:14 -05:00
|
|
|
fn maybe_side_effect() -> bool {
|
2023-06-11 06:50:03 -05:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2023-06-10 06:43:30 -05:00
|
|
|
fn main() {
|
|
|
|
// Lint
|
2023-06-11 06:50:03 -05:00
|
|
|
|
|
|
|
// Do not remove the condition
|
2023-06-12 10:05:14 -05:00
|
|
|
maybe_side_effect();
|
2023-06-10 06:43:30 -05:00
|
|
|
// Do not lint
|
|
|
|
if (true) {
|
|
|
|
} else {
|
|
|
|
}
|
2023-06-12 10:05:14 -05:00
|
|
|
({
|
2023-06-11 06:50:03 -05:00
|
|
|
return;
|
2023-06-12 10:05:14 -05:00
|
|
|
});
|
2023-06-10 06:43:30 -05:00
|
|
|
// Do not lint if `else if` is present
|
|
|
|
if (true) {
|
|
|
|
} else if (true) {
|
|
|
|
}
|
2023-06-12 10:05:14 -05:00
|
|
|
// Do not lint `if let` or let chains
|
2023-06-11 06:50:03 -05:00
|
|
|
if let true = true {}
|
|
|
|
if let true = true && true {}
|
|
|
|
if true && let true = true {}
|
2023-06-12 10:05:14 -05:00
|
|
|
// Can lint nested `if let`s
|
|
|
|
({
|
2023-06-11 07:12:46 -05:00
|
|
|
if let true = true && true { true } else { false }
|
2023-06-12 10:05:14 -05:00
|
|
|
} && true);
|
2023-06-10 06:43:30 -05:00
|
|
|
external! { if (true) {} }
|
|
|
|
with_span! {
|
|
|
|
span
|
|
|
|
if (true) {}
|
|
|
|
}
|
2023-06-12 10:05:14 -05:00
|
|
|
|
|
|
|
if true {
|
|
|
|
// comment
|
|
|
|
}
|
|
|
|
|
|
|
|
if true {
|
|
|
|
#[cfg(any())]
|
|
|
|
foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! empty_expansion {
|
|
|
|
() => {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if true {
|
|
|
|
empty_expansion!();
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! empty_repetition {
|
|
|
|
($($t:tt)*) => {
|
|
|
|
if true {
|
|
|
|
$($t)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
empty_repetition!();
|
|
|
|
|
|
|
|
// Must be placed into an expression context to not be interpreted as a block
|
|
|
|
({ maybe_side_effect() });
|
|
|
|
// Would be a block followed by `&&true` - a double reference to `true`
|
|
|
|
({ maybe_side_effect() } && true);
|
|
|
|
|
|
|
|
// Don't leave trailing attributes
|
|
|
|
#[allow(unused)]
|
|
|
|
true;
|
|
|
|
|
|
|
|
let () = if maybe_side_effect() {};
|
2023-06-10 06:43:30 -05:00
|
|
|
}
|