2023-06-10 11:43:30 +00:00
|
|
|
//@run-rustfix
|
|
|
|
//@aux-build:proc_macros.rs
|
2023-06-11 11:50:03 +00:00
|
|
|
#![feature(let_chains)]
|
2023-06-10 11:43:30 +00:00
|
|
|
#![allow(
|
|
|
|
clippy::blocks_in_if_conditions,
|
|
|
|
clippy::if_same_then_else,
|
|
|
|
clippy::ifs_same_cond,
|
|
|
|
clippy::needless_else,
|
|
|
|
clippy::no_effect,
|
2023-06-11 11:50:03 +00:00
|
|
|
clippy::nonminimal_bool,
|
2023-06-10 11:43:30 +00:00
|
|
|
unused
|
|
|
|
)]
|
|
|
|
#![warn(clippy::needless_if)]
|
|
|
|
|
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::external;
|
|
|
|
use proc_macros::with_span;
|
|
|
|
|
2023-06-11 11:50:03 +00:00
|
|
|
fn no_side_effects() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn has_side_effects(a: &mut u32) -> bool {
|
|
|
|
*a = 1;
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2023-06-10 11:43:30 +00:00
|
|
|
fn main() {
|
|
|
|
// Lint
|
|
|
|
if (true) {}
|
2023-06-11 11:50:03 +00:00
|
|
|
// Do not remove the condition
|
|
|
|
if no_side_effects() {}
|
|
|
|
let mut x = 0;
|
|
|
|
if has_side_effects(&mut x) {}
|
|
|
|
assert_eq!(x, 1);
|
2023-06-10 11:43:30 +00:00
|
|
|
// Do not lint
|
|
|
|
if (true) {
|
|
|
|
} else {
|
|
|
|
}
|
2023-06-11 11:50:03 +00:00
|
|
|
if {
|
|
|
|
return;
|
|
|
|
} {}
|
2023-06-10 11:43:30 +00:00
|
|
|
// Do not lint if `else if` is present
|
|
|
|
if (true) {
|
|
|
|
} else if (true) {
|
|
|
|
}
|
2023-06-11 11:50:03 +00:00
|
|
|
// Do not lint if any `let` is present
|
|
|
|
if let true = true {}
|
|
|
|
if let true = true && true {}
|
|
|
|
if true && let true = true {}
|
2023-06-10 11:43:30 +00:00
|
|
|
if {
|
2023-06-11 11:50:03 +00:00
|
|
|
if let true = true && true { true } else { false }
|
|
|
|
} && true
|
|
|
|
{}
|
2023-06-10 11:43:30 +00:00
|
|
|
external! { if (true) {} }
|
|
|
|
with_span! {
|
|
|
|
span
|
|
|
|
if (true) {}
|
|
|
|
}
|
|
|
|
}
|