about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2022-06-25 14:16:30 +0200
committerxFrednet <xFrednet@gmail.com>2022-06-25 14:16:30 +0200
commita3c7101f61ae4f608b040c2c896b39570bfed38c (patch)
tree0d7255cb2d95004d5dba62aed830cb53a1334fee
parent811d73a2b7ff6af1aacdbe45520ff874a3371269 (diff)
downloadrust-a3c7101f61ae4f608b040c2c896b39570bfed38c.tar.gz
rust-a3c7101f61ae4f608b040c2c896b39570bfed38c.zip
Fix `#[expect]` for `clippy::logic_bug`
-rw-r--r--clippy_lints/src/booleans.rs5
-rw-r--r--tests/ui/logic_bug.rs8
-rw-r--r--tests/ui/logic_bug.stderr20
3 files changed, 21 insertions, 12 deletions
diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs
index e4e122ba6eb..96a2d158514 100644
--- a/clippy_lints/src/booleans.rs
+++ b/clippy_lints/src/booleans.rs
@@ -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| {
diff --git a/tests/ui/logic_bug.rs b/tests/ui/logic_bug.rs
index 4eaa2dd98eb..dd6b1db5f70 100644
--- a/tests/ui/logic_bug.rs
+++ b/tests/ui/logic_bug.rs
@@ -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;
+}
diff --git a/tests/ui/logic_bug.stderr b/tests/ui/logic_bug.stderr
index 8f55e1c8ad8..4021fbf4570 100644
--- a/tests/ui/logic_bug.stderr
+++ b/tests/ui/logic_bug.stderr
@@ -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;
    |             ^^^^^