Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b6ee6bb

Browse files
committed
Fix #[expect] for clippy::nonminimal_bool
1 parent a3c7101 commit b6ee6bb

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

clippy_lints/src/booleans.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then};
1+
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22
use clippy_utils::source::snippet_opt;
33
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
44
use clippy_utils::{eq_expr_value, get_trait_def_id, paths};
@@ -430,9 +430,10 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
430430
}
431431
}
432432
let nonminimal_bool_lint = |suggestions: Vec<_>| {
433-
span_lint_and_then(
433+
span_lint_hir_and_then(
434434
self.cx,
435435
NONMINIMAL_BOOL,
436+
e.hir_id,
436437
e.span,
437438
"this boolean expression can be simplified",
438439
|diag| {

tests/ui/nonminimal_bool.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(lint_reasons)]
12
#![allow(unused, clippy::diverging_sub_expression)]
23
#![warn(clippy::nonminimal_bool)]
34

@@ -50,3 +51,9 @@ fn issue4548() {
5051

5152
if i != j && f(i, j) != 0 || i == j && f(i, j) != 1 {}
5253
}
54+
55+
fn check_expect() {
56+
let a: bool = unimplemented!();
57+
#[expect(clippy::nonminimal_bool)]
58+
let _ = !!a;
59+
}

tests/ui/nonminimal_bool.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: this boolean expression can be simplified
2-
--> $DIR/nonminimal_bool.rs:10:13
2+
--> $DIR/nonminimal_bool.rs:11:13
33
|
44
LL | let _ = !true;
55
| ^^^^^ help: try: `false`
66
|
77
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
88

99
error: this boolean expression can be simplified
10-
--> $DIR/nonminimal_bool.rs:11:13
10+
--> $DIR/nonminimal_bool.rs:12:13
1111
|
1212
LL | let _ = !false;
1313
| ^^^^^^ help: try: `true`
1414

1515
error: this boolean expression can be simplified
16-
--> $DIR/nonminimal_bool.rs:12:13
16+
--> $DIR/nonminimal_bool.rs:13:13
1717
|
1818
LL | let _ = !!a;
1919
| ^^^ help: try: `a`
2020

2121
error: this boolean expression can be simplified
22-
--> $DIR/nonminimal_bool.rs:13:13
22+
--> $DIR/nonminimal_bool.rs:14:13
2323
|
2424
LL | let _ = false || a;
2525
| ^^^^^^^^^^ help: try: `a`
2626

2727
error: this boolean expression can be simplified
28-
--> $DIR/nonminimal_bool.rs:17:13
28+
--> $DIR/nonminimal_bool.rs:18:13
2929
|
3030
LL | let _ = !(!a && b);
3131
| ^^^^^^^^^^ help: try: `a || !b`
3232

3333
error: this boolean expression can be simplified
34-
--> $DIR/nonminimal_bool.rs:18:13
34+
--> $DIR/nonminimal_bool.rs:19:13
3535
|
3636
LL | let _ = !(!a || b);
3737
| ^^^^^^^^^^ help: try: `a && !b`
3838

3939
error: this boolean expression can be simplified
40-
--> $DIR/nonminimal_bool.rs:19:13
40+
--> $DIR/nonminimal_bool.rs:20:13
4141
|
4242
LL | let _ = !a && !(b && c);
4343
| ^^^^^^^^^^^^^^^ help: try: `!(a || b && c)`
4444

4545
error: this boolean expression can be simplified
46-
--> $DIR/nonminimal_bool.rs:27:13
46+
--> $DIR/nonminimal_bool.rs:28:13
4747
|
4848
LL | let _ = a == b && c == 5 && a == b;
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -56,7 +56,7 @@ LL | let _ = a == b && c == 5;
5656
| ~~~~~~~~~~~~~~~~
5757

5858
error: this boolean expression can be simplified
59-
--> $DIR/nonminimal_bool.rs:28:13
59+
--> $DIR/nonminimal_bool.rs:29:13
6060
|
6161
LL | let _ = a == b || c == 5 || a == b;
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -69,7 +69,7 @@ LL | let _ = a == b || c == 5;
6969
| ~~~~~~~~~~~~~~~~
7070

7171
error: this boolean expression can be simplified
72-
--> $DIR/nonminimal_bool.rs:29:13
72+
--> $DIR/nonminimal_bool.rs:30:13
7373
|
7474
LL | let _ = a == b && c == 5 && b == a;
7575
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -82,7 +82,7 @@ LL | let _ = a == b && c == 5;
8282
| ~~~~~~~~~~~~~~~~
8383

8484
error: this boolean expression can be simplified
85-
--> $DIR/nonminimal_bool.rs:30:13
85+
--> $DIR/nonminimal_bool.rs:31:13
8686
|
8787
LL | let _ = a != b || !(a != b || c == d);
8888
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,7 +95,7 @@ LL | let _ = a != b || c != d;
9595
| ~~~~~~~~~~~~~~~~
9696

9797
error: this boolean expression can be simplified
98-
--> $DIR/nonminimal_bool.rs:31:13
98+
--> $DIR/nonminimal_bool.rs:32:13
9999
|
100100
LL | let _ = a != b && !(a != b && c == d);
101101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)