don't lint on if let
don't lint on `if let`
This commit is contained in:
parent
b2bdc37a55
commit
59bca098f9
4 changed files with 109 additions and 25 deletions
|
|
@ -1,11 +1,13 @@
|
|||
//@run-rustfix
|
||||
//@aux-build:proc_macros.rs
|
||||
#![feature(let_chains)]
|
||||
#![allow(
|
||||
clippy::blocks_in_if_conditions,
|
||||
clippy::if_same_then_else,
|
||||
clippy::ifs_same_cond,
|
||||
clippy::needless_else,
|
||||
clippy::no_effect,
|
||||
clippy::nonminimal_bool,
|
||||
unused
|
||||
)]
|
||||
#![warn(clippy::needless_if)]
|
||||
|
|
@ -14,21 +16,39 @@ extern crate proc_macros;
|
|||
use proc_macros::external;
|
||||
use proc_macros::with_span;
|
||||
|
||||
fn no_side_effects() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn has_side_effects(a: &mut u32) -> bool {
|
||||
*a = 1;
|
||||
true
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Lint
|
||||
(true);
|
||||
|
||||
// Do not remove the condition
|
||||
no_side_effects();
|
||||
let mut x = 0;
|
||||
has_side_effects(&mut x);
|
||||
assert_eq!(x, 1);
|
||||
// Do not lint
|
||||
if (true) {
|
||||
} else {
|
||||
}
|
||||
{
|
||||
return;
|
||||
};
|
||||
// Do not lint if `else if` is present
|
||||
if (true) {
|
||||
} else if (true) {
|
||||
}
|
||||
// Ensure clippy does not bork this up, other cases should be added
|
||||
{
|
||||
return;
|
||||
};
|
||||
// Do not lint if any `let` is present
|
||||
if let true = true {}
|
||||
if let true = true && true {}
|
||||
if true && let true = true {}
|
||||
if { if let true = true && true { true } else { false } } && true {}
|
||||
external! { if (true) {} }
|
||||
with_span! {
|
||||
span
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
//@run-rustfix
|
||||
//@aux-build:proc_macros.rs
|
||||
#![feature(let_chains)]
|
||||
#![allow(
|
||||
clippy::blocks_in_if_conditions,
|
||||
clippy::if_same_then_else,
|
||||
clippy::ifs_same_cond,
|
||||
clippy::needless_else,
|
||||
clippy::no_effect,
|
||||
clippy::nonminimal_bool,
|
||||
unused
|
||||
)]
|
||||
#![warn(clippy::needless_if)]
|
||||
|
|
@ -14,21 +16,42 @@ extern crate proc_macros;
|
|||
use proc_macros::external;
|
||||
use proc_macros::with_span;
|
||||
|
||||
fn no_side_effects() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn has_side_effects(a: &mut u32) -> bool {
|
||||
*a = 1;
|
||||
true
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Lint
|
||||
if (true) {}
|
||||
// Do not remove the condition
|
||||
if no_side_effects() {}
|
||||
let mut x = 0;
|
||||
if has_side_effects(&mut x) {}
|
||||
assert_eq!(x, 1);
|
||||
// Do not lint
|
||||
if (true) {
|
||||
} else {
|
||||
}
|
||||
if {
|
||||
return;
|
||||
} {}
|
||||
// Do not lint if `else if` is present
|
||||
if (true) {
|
||||
} else if (true) {
|
||||
}
|
||||
// Ensure clippy does not bork this up, other cases should be added
|
||||
// Do not lint if any `let` is present
|
||||
if let true = true {}
|
||||
if let true = true && true {}
|
||||
if true && let true = true {}
|
||||
if {
|
||||
return;
|
||||
} {}
|
||||
if let true = true && true { true } else { false }
|
||||
} && true
|
||||
{}
|
||||
external! { if (true) {} }
|
||||
with_span! {
|
||||
span
|
||||
|
|
|
|||
|
|
@ -1,13 +1,25 @@
|
|||
error: this if branch is empty
|
||||
--> $DIR/needless_if.rs:19:5
|
||||
error: this `if` branch is empty
|
||||
--> $DIR/needless_if.rs:30:5
|
||||
|
|
||||
LL | if (true) {}
|
||||
| ^^^^^^^^^^^^ help: you can remove it: `(true);`
|
||||
| ^^^^^^^^^^^^ help: you can remove it
|
||||
|
|
||||
= note: `-D clippy::needless-if` implied by `-D warnings`
|
||||
|
||||
error: this if branch is empty
|
||||
--> $DIR/needless_if.rs:29:5
|
||||
error: this `if` branch is empty
|
||||
--> $DIR/needless_if.rs:32:5
|
||||
|
|
||||
LL | if no_side_effects() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `no_side_effects();`
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> $DIR/needless_if.rs:34:5
|
||||
|
|
||||
LL | if has_side_effects(&mut x) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can remove it: `has_side_effects(&mut x);`
|
||||
|
||||
error: this `if` branch is empty
|
||||
--> $DIR/needless_if.rs:40:5
|
||||
|
|
||||
LL | / if {
|
||||
LL | | return;
|
||||
|
|
@ -21,5 +33,5 @@ LL + return;
|
|||
LL + };
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue