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

Commit a3c7101

Browse files
committed
Fix #[expect] for clippy::logic_bug
1 parent 811d73a commit a3c7101

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
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};
1+
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then, 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};
@@ -394,9 +394,10 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
394394
continue 'simplified;
395395
}
396396
if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 {
397-
span_lint_and_then(
397+
span_lint_hir_and_then(
398398
self.cx,
399399
LOGIC_BUG,
400+
e.hir_id,
400401
e.span,
401402
"this boolean expression contains a logic bug",
402403
|diag| {

tests/ui/logic_bug.rs

Lines changed: 8 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::logic_bug)]
34

@@ -24,3 +25,10 @@ fn equality_stuff() {
2425
let _ = a > b && a <= b;
2526
let _ = a > b && a == b;
2627
}
28+
29+
fn check_expect() {
30+
let a: i32 = unimplemented!();
31+
let b: i32 = unimplemented!();
32+
#[expect(clippy::logic_bug)]
33+
let _ = a < b && a >= b;
34+
}

tests/ui/logic_bug.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
error: this boolean expression contains a logic bug
2-
--> $DIR/logic_bug.rs:10:13
2+
--> $DIR/logic_bug.rs:11:13
33
|
44
LL | let _ = a && b || a;
55
| ^^^^^^^^^^^ help: it would look like the following: `a`
66
|
77
= note: `-D clippy::logic-bug` implied by `-D warnings`
88
help: this expression can be optimized out by applying boolean operations to the outer expression
9-
--> $DIR/logic_bug.rs:10:18
9+
--> $DIR/logic_bug.rs:11:18
1010
|
1111
LL | let _ = a && b || a;
1212
| ^
1313

1414
error: this boolean expression contains a logic bug
15-
--> $DIR/logic_bug.rs:12:13
15+
--> $DIR/logic_bug.rs:13:13
1616
|
1717
LL | let _ = false && a;
1818
| ^^^^^^^^^^ help: it would look like the following: `false`
1919
|
2020
help: this expression can be optimized out by applying boolean operations to the outer expression
21-
--> $DIR/logic_bug.rs:12:22
21+
--> $DIR/logic_bug.rs:13:22
2222
|
2323
LL | let _ = false && a;
2424
| ^
2525

2626
error: this boolean expression contains a logic bug
27-
--> $DIR/logic_bug.rs:22:13
27+
--> $DIR/logic_bug.rs:23:13
2828
|
2929
LL | let _ = a == b && a != b;
3030
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
3131
|
3232
help: this expression can be optimized out by applying boolean operations to the outer expression
33-
--> $DIR/logic_bug.rs:22:13
33+
--> $DIR/logic_bug.rs:23:13
3434
|
3535
LL | let _ = a == b && a != b;
3636
| ^^^^^^
3737

3838
error: this boolean expression contains a logic bug
39-
--> $DIR/logic_bug.rs:23:13
39+
--> $DIR/logic_bug.rs:24:13
4040
|
4141
LL | let _ = a < b && a >= b;
4242
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
4343
|
4444
help: this expression can be optimized out by applying boolean operations to the outer expression
45-
--> $DIR/logic_bug.rs:23:13
45+
--> $DIR/logic_bug.rs:24:13
4646
|
4747
LL | let _ = a < b && a >= b;
4848
| ^^^^^
4949

5050
error: this boolean expression contains a logic bug
51-
--> $DIR/logic_bug.rs:24:13
51+
--> $DIR/logic_bug.rs:25:13
5252
|
5353
LL | let _ = a > b && a <= b;
5454
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
5555
|
5656
help: this expression can be optimized out by applying boolean operations to the outer expression
57-
--> $DIR/logic_bug.rs:24:13
57+
--> $DIR/logic_bug.rs:25:13
5858
|
5959
LL | let _ = a > b && a <= b;
6060
| ^^^^^

0 commit comments

Comments
 (0)