Fix #[expect] for clippy::logic_bug

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

View file

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

View file

@ -1,3 +1,4 @@
#![feature(lint_reasons)]
#![allow(unused, clippy::diverging_sub_expression)]
#![warn(clippy::logic_bug)]
@ -24,3 +25,10 @@ fn equality_stuff() {
let _ = a > b && a <= b;
let _ = a > b && a == b;
}
fn check_expect() {
let a: i32 = unimplemented!();
let b: i32 = unimplemented!();
#[expect(clippy::logic_bug)]
let _ = a < b && a >= b;
}

View file

@ -1,60 +1,60 @@
error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:10:13
--> $DIR/logic_bug.rs:11:13
|
LL | let _ = a && b || a;
| ^^^^^^^^^^^ help: it would look like the following: `a`
|
= note: `-D clippy::logic-bug` implied by `-D warnings`
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:10:18
--> $DIR/logic_bug.rs:11:18
|
LL | let _ = a && b || a;
| ^
error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:12:13
--> $DIR/logic_bug.rs:13:13
|
LL | let _ = false && a;
| ^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:12:22
--> $DIR/logic_bug.rs:13:22
|
LL | let _ = false && a;
| ^
error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:22:13
--> $DIR/logic_bug.rs:23:13
|
LL | let _ = a == b && a != b;
| ^^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:22:13
--> $DIR/logic_bug.rs:23:13
|
LL | let _ = a == b && a != b;
| ^^^^^^
error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:23:13
--> $DIR/logic_bug.rs:24:13
|
LL | let _ = a < b && a >= b;
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:23:13
--> $DIR/logic_bug.rs:24:13
|
LL | let _ = a < b && a >= b;
| ^^^^^
error: this boolean expression contains a logic bug
--> $DIR/logic_bug.rs:24:13
--> $DIR/logic_bug.rs:25:13
|
LL | let _ = a > b && a <= b;
| ^^^^^^^^^^^^^^^ help: it would look like the following: `false`
|
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/logic_bug.rs:24:13
--> $DIR/logic_bug.rs:25:13
|
LL | let _ = a > b && a <= b;
| ^^^^^