2023-08-24 14:32:12 -05:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-07-02 07:35:19 -05:00
|
|
|
#![feature(let_chains)]
|
|
|
|
#![allow(
|
2023-12-16 07:12:50 -06:00
|
|
|
clippy::blocks_in_conditions,
|
2023-07-02 07:35:19 -05:00
|
|
|
clippy::if_same_then_else,
|
|
|
|
clippy::ifs_same_cond,
|
|
|
|
clippy::let_unit_value,
|
|
|
|
clippy::needless_else,
|
|
|
|
clippy::no_effect,
|
|
|
|
clippy::nonminimal_bool,
|
|
|
|
clippy::short_circuit_statement,
|
|
|
|
clippy::unnecessary_operation,
|
2023-12-28 12:33:07 -06:00
|
|
|
clippy::redundant_pattern_matching,
|
2023-07-02 07:35:19 -05:00
|
|
|
unused
|
|
|
|
)]
|
|
|
|
#![warn(clippy::needless_if)]
|
|
|
|
|
|
|
|
extern crate proc_macros;
|
2023-07-17 03:19:29 -05:00
|
|
|
use proc_macros::{external, with_span};
|
2023-07-02 07:35:19 -05:00
|
|
|
|
|
|
|
fn maybe_side_effect() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Lint
|
|
|
|
|
|
|
|
// Do not remove the condition
|
|
|
|
maybe_side_effect();
|
|
|
|
// Do not lint
|
|
|
|
if (true) {
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
({
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
// Do not lint if `else if` is present
|
|
|
|
if (true) {
|
|
|
|
} else if (true) {
|
|
|
|
}
|
|
|
|
// Do not lint `if let` or let chains
|
|
|
|
if let true = true {}
|
2023-11-02 11:35:56 -05:00
|
|
|
if let true = true
|
|
|
|
&& true
|
|
|
|
{}
|
|
|
|
if true
|
|
|
|
&& let true = true
|
|
|
|
{}
|
2023-07-02 07:35:19 -05:00
|
|
|
// Can lint nested `if let`s
|
|
|
|
({
|
2023-11-02 11:35:56 -05:00
|
|
|
if let true = true
|
|
|
|
&& true
|
|
|
|
{
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
2023-07-02 07:35:19 -05:00
|
|
|
} && true);
|
|
|
|
external! { if (true) {} }
|
|
|
|
with_span! {
|
|
|
|
span
|
|
|
|
if (true) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {};
|
|
|
|
}
|