Fix #[expect] for clippy::nonminimal_bool

This commit is contained in:
xFrednet 2022-06-25 14:16:30 +02:00
parent a3c7101f61
commit b6ee6bba4c
No known key found for this signature in database
GPG key ID: F5C59D0E669E5302
3 changed files with 22 additions and 14 deletions

View file

@ -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::source::snippet_opt;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item}; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
use clippy_utils::{eq_expr_value, get_trait_def_id, paths}; 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<_>| { let nonminimal_bool_lint = |suggestions: Vec<_>| {
span_lint_and_then( span_lint_hir_and_then(
self.cx, self.cx,
NONMINIMAL_BOOL, NONMINIMAL_BOOL,
e.hir_id,
e.span, e.span,
"this boolean expression can be simplified", "this boolean expression can be simplified",
|diag| { |diag| {

View file

@ -1,3 +1,4 @@
#![feature(lint_reasons)]
#![allow(unused, clippy::diverging_sub_expression)] #![allow(unused, clippy::diverging_sub_expression)]
#![warn(clippy::nonminimal_bool)] #![warn(clippy::nonminimal_bool)]
@ -50,3 +51,9 @@ fn issue4548() {
if i != j && f(i, j) != 0 || i == j && f(i, j) != 1 {} 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;
}

View file

@ -1,5 +1,5 @@
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:10:13 --> $DIR/nonminimal_bool.rs:11:13
| |
LL | let _ = !true; LL | let _ = !true;
| ^^^^^ help: try: `false` | ^^^^^ help: try: `false`
@ -7,43 +7,43 @@ LL | let _ = !true;
= note: `-D clippy::nonminimal-bool` implied by `-D warnings` = note: `-D clippy::nonminimal-bool` implied by `-D warnings`
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:11:13 --> $DIR/nonminimal_bool.rs:12:13
| |
LL | let _ = !false; LL | let _ = !false;
| ^^^^^^ help: try: `true` | ^^^^^^ help: try: `true`
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:12:13 --> $DIR/nonminimal_bool.rs:13:13
| |
LL | let _ = !!a; LL | let _ = !!a;
| ^^^ help: try: `a` | ^^^ help: try: `a`
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:13:13 --> $DIR/nonminimal_bool.rs:14:13
| |
LL | let _ = false || a; LL | let _ = false || a;
| ^^^^^^^^^^ help: try: `a` | ^^^^^^^^^^ help: try: `a`
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:17:13 --> $DIR/nonminimal_bool.rs:18:13
| |
LL | let _ = !(!a && b); LL | let _ = !(!a && b);
| ^^^^^^^^^^ help: try: `a || !b` | ^^^^^^^^^^ help: try: `a || !b`
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:18:13 --> $DIR/nonminimal_bool.rs:19:13
| |
LL | let _ = !(!a || b); LL | let _ = !(!a || b);
| ^^^^^^^^^^ help: try: `a && !b` | ^^^^^^^^^^ help: try: `a && !b`
error: this boolean expression can be simplified error: this boolean expression can be simplified
--> $DIR/nonminimal_bool.rs:19:13 --> $DIR/nonminimal_bool.rs:20:13
| |
LL | let _ = !a && !(b && c); LL | let _ = !a && !(b && c);
| ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)` | ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)`
error: this boolean expression can be simplified 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; 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 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; 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 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; 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 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); 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 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); LL | let _ = a != b && !(a != b && c == d);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^