mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Fix #[expect]
for clippy::nonminimal_bool
This commit is contained in:
parent
a3c7101f61
commit
b6ee6bba4c
3 changed files with 22 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then};
|
||||
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
|
||||
use clippy_utils::source::snippet_opt;
|
||||
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
|
||||
use clippy_utils::{eq_expr_value, get_trait_def_id, paths};
|
||||
|
@ -430,9 +430,10 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
let nonminimal_bool_lint = |suggestions: Vec<_>| {
|
||||
span_lint_and_then(
|
||||
span_lint_hir_and_then(
|
||||
self.cx,
|
||||
NONMINIMAL_BOOL,
|
||||
e.hir_id,
|
||||
e.span,
|
||||
"this boolean expression can be simplified",
|
||||
|diag| {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![feature(lint_reasons)]
|
||||
#![allow(unused, clippy::diverging_sub_expression)]
|
||||
#![warn(clippy::nonminimal_bool)]
|
||||
|
||||
|
@ -50,3 +51,9 @@ fn issue4548() {
|
|||
|
||||
if i != j && f(i, j) != 0 || i == j && f(i, j) != 1 {}
|
||||
}
|
||||
|
||||
fn check_expect() {
|
||||
let a: bool = unimplemented!();
|
||||
#[expect(clippy::nonminimal_bool)]
|
||||
let _ = !!a;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:10:13
|
||||
--> $DIR/nonminimal_bool.rs:11:13
|
||||
|
|
||||
LL | let _ = !true;
|
||||
| ^^^^^ help: try: `false`
|
||||
|
@ -7,43 +7,43 @@ LL | let _ = !true;
|
|||
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:11:13
|
||||
--> $DIR/nonminimal_bool.rs:12:13
|
||||
|
|
||||
LL | let _ = !false;
|
||||
| ^^^^^^ help: try: `true`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:12:13
|
||||
--> $DIR/nonminimal_bool.rs:13:13
|
||||
|
|
||||
LL | let _ = !!a;
|
||||
| ^^^ help: try: `a`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:13:13
|
||||
--> $DIR/nonminimal_bool.rs:14:13
|
||||
|
|
||||
LL | let _ = false || a;
|
||||
| ^^^^^^^^^^ help: try: `a`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:17:13
|
||||
--> $DIR/nonminimal_bool.rs:18:13
|
||||
|
|
||||
LL | let _ = !(!a && b);
|
||||
| ^^^^^^^^^^ help: try: `a || !b`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:18:13
|
||||
--> $DIR/nonminimal_bool.rs:19:13
|
||||
|
|
||||
LL | let _ = !(!a || b);
|
||||
| ^^^^^^^^^^ help: try: `a && !b`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:19:13
|
||||
--> $DIR/nonminimal_bool.rs:20:13
|
||||
|
|
||||
LL | let _ = !a && !(b && c);
|
||||
| ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)`
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:27:13
|
||||
--> $DIR/nonminimal_bool.rs:28:13
|
||||
|
|
||||
LL | let _ = a == b && c == 5 && a == b;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -56,7 +56,7 @@ LL | let _ = a == b && c == 5;
|
|||
| ~~~~~~~~~~~~~~~~
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:28:13
|
||||
--> $DIR/nonminimal_bool.rs:29:13
|
||||
|
|
||||
LL | let _ = a == b || c == 5 || a == b;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -69,7 +69,7 @@ LL | let _ = a == b || c == 5;
|
|||
| ~~~~~~~~~~~~~~~~
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:29:13
|
||||
--> $DIR/nonminimal_bool.rs:30:13
|
||||
|
|
||||
LL | let _ = a == b && c == 5 && b == a;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -82,7 +82,7 @@ LL | let _ = a == b && c == 5;
|
|||
| ~~~~~~~~~~~~~~~~
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:30:13
|
||||
--> $DIR/nonminimal_bool.rs:31:13
|
||||
|
|
||||
LL | let _ = a != b || !(a != b || c == d);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -95,7 +95,7 @@ LL | let _ = a != b || c != d;
|
|||
| ~~~~~~~~~~~~~~~~
|
||||
|
||||
error: this boolean expression can be simplified
|
||||
--> $DIR/nonminimal_bool.rs:31:13
|
||||
--> $DIR/nonminimal_bool.rs:32:13
|
||||
|
|
||||
LL | let _ = a != b && !(a != b && c == d);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue